版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_36373500/article/details/86537007
使用过程中注意
安装了MSYS2之后,需要使用
pacman -S base-devel
安装编译环境,否则报错
autoreconf: command not found
==> ERROR: A failure occurred in prepare().
Aborting...
Protobuf-c Win-platform binaries, built with MSYS2, test on STM32F446 (IDE: Keil5).
Using https://github.com/protobuf-c/protobuf-c.
How to use gen.exe?
- Open a terminal.
- Type
gen --help
. - OK! Now you know HOW.
How to compile with Keil5?
- Add protobuf-c folder to your project.
- Generate your files use gen.exe, then add them to your project.
- Write your program, according to files in test folder.
- DO NOT USE MicroLib.
How to compile protoc.exe?
-
Install MSYS2.
-
New a folder, for example, pbc.
-
Enter pbc, new a file named "PKGBUILD".
-
Fill the file with the code below.
# Maintainer: Alexey Pavlov <[email protected]> _realname=protobuf-c pkgbase=mingw-w64-${_realname} pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}" pkgver=1.3.1 pkgrel=1 pkgdesc="Protocol Buffers implementation in C (mingw-w64)" arch=('any') url="https://github.com/protobuf-c/protobuf-c" license=('BSD') depends=("${MINGW_PACKAGE_PREFIX}-protobuf") makedepends=("${MINGW_PACKAGE_PREFIX}-gcc") options=('staticlibs' 'strip') source=("$url/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.gz") sha256sums=('51472d3a191d6d7b425e32b612e477c06f73fe23e07f6a6a839b11808e9d2267') prepare() { cd "${srcdir}/${_realname}-${pkgver}" autoreconf -fiv } build() { [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}" mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}" ../${_realname}-${pkgver}/configure \ --prefix=${MINGW_PREFIX} \ --build=${MINGW_CHOST} \ --host=${MINGW_CHOST} make } check() { cd "${srcdir}/build-${MINGW_CHOST}" make check || true } package() { cd "${srcdir}/build-${MINGW_CHOST}" make DESTDIR="${pkgdir}" install install -Dm644 ${srcdir}/${_realname}-${pkgver}/LICENSE "${pkgdir}${MINGW_PREFIX}"/share/licenses/${_realname}/LICENSE }
-
Open a terminal in this folder, type
MINGW_INSTALLS=mingw64 makepkg-mingw -sLf
. -
Wait for compiling done.
-
Install the lib you have just compiled.
type
pacman -U mingw-w64-x86_64-protobuf-c*.pkg.tar.xz
, enter. -
Copy your protoc.exe from
<your MSYS2 path>/mingw64/bin
. -
Do what you want.