创建交叉编译环境时
在Linux下安装Mingw32,使用Mingw32编译windows的应用程序,经常会使用到一些第三方的开源库,此时需要将开源库安装进mingw32中,以便在交叉编译时可以找到对应的头文件和库文件;
在使用Boost库时,遇到的编译问题,由于网上大部分都是在windows上的mingw32中编译安装,跟Linux还是又许多差距的;在使用过程中也遇到了很多问题,在Stackoverflow上终于找到了对应的解决办法,现将记录如下:
链接: 解决办法
1. echo "using gcc : : x86_64-w64-mingw32-g++ ;" > user-config.jam **
2. ./bootstrap.sh **
3. ./b2 --user-config=user-config.jam toolset=gcc-mingw target-os=windows release**
或者
//编译32位
./b2 --user-config=./user-config.jam --prefix=/usr/x86_64-w64-mingw32/sys-root/mingw target-os=windows address-model=32 variant=release install
//编译64位
./b2 --user-config=./user-config.jam --prefix=/usr/x86_64-w64-mingw32/sys-root/mingw target-os=windows address-model=64 variant=release install
使用protobuf-c开源库时的编译方式:
yum install mingw32-protobuf mingw64-protobuf
git clone https://github.com/protobuf-c/protobuf-c.git
cd protobuf-c
git reset --hard 269771b //切换protobuf-c的版本tag
cd build-cmake
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig // 指定protobuf.pc文件所在
//32位
mingw32-cmake -DCMAKE_INSTALL_PREFIX=/usr/x86_64-w64-mingw32/sys-root/mingw ./
//64位
mingw64-cmake -DCMAKE_INSTALL_PREFIX=/usr/x86_64-w64-mingw32/sys-root/mingw ./
make
make install
protobuf-c编译完成应该会生成一个libprotobuf-c.pc文件,如果没有,可以模拟一个,主要修改prefix
,修改完后这个文件应该放置“/usr/x86_64-w64-mingw32/sys-root/mingw/lib/pkgconfig”
prefix=/usr/i686-w64-mingw32/sys-root/mingw
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include
Name: libprotobuf-c
Description: Protocol Buffers C library
Version: 1.0.2
Libs: -L${libdir} -lprotobuf-c
Libs.private:
Cflags: -I${includedir}
protoc 利用.proto文件生成 C或者 CPP文件
./protoc --c_out=./ fuse_message.proto 会在当前路径下生成fuse_message.pb-c.h fuse_message.pb-c.c
./protoc --cpp_out=./ fuse_message.proto 会在当前路径下生成fuse_message.pb.h fuse_message.pb.cc
windows下使用例子
.\protoc.exe --proto_path=..\data --cpp_out=../data/ ..\data\deviceConfig.proto