-
Protobuf github 官网 GitHub - protocolbuffers/protobuf: Protocol Buffers - Google's data interchange format
- 我们一般使用2.6.1
-
先编译PC版本(此步骤很重要 因为需要proto-c生成代码)
-
解压protobuf-2.6.1.tar.gz
-
./autogen.sh
直接执行会报错 可以把./autogen.sh
脚本里这部分替换
-
-
echo "Google Test not present. Fetching gtest-1.5.0 from the web..." curl <http://googletest.googlecode.com/files/gtest-1.5.0.tar.bz2> | tar jx mv gtest-1.5.0 gtest
wget <https://github.com/google/googletest/archive/release-1.5.0.tar.gz> tar xzvf release-1.5.0.tar.gz #发现下载的文件没有后缀名,所以我改成tar xzvf release-1.5.0 mv googletest-release-1.5.0 gtest
再次执行
./autogen.sh
./configure --prefix=/home/work/protobuf/pc_protobuf
-
make install
(注意权限) -
make
-
-
交叉编译
-
跑下以下脚本
#!/bin/bash compiler_root_path="/home/softwares/gcc-linaro-6.5.0-2018.12-x86_64_aarch64-linux-gnu" make_c_compiler=${compiler_root_path}/bin/aarch64-linux-gnu-gcc make_cxx_compiler=${compiler_root_path}/bin/aarch64-linux-gnu-g++ echo ${make_c_compiler} echo ${make_cxx_compiler} ./configure --host=arm-linux CC=${make_c_compiler} CXX=${make_cxx_compiler} CXXFLAGS=-fPIC --prefix=/home/work/protobuff/arm_protobuf/ --disable-dependency-tracking --with-protoc=/home/work/protobuf/pc_protobuf/bin/protoc
注意:
1.要配置好交叉编译工具
2.一定要加上编译选项 CXXFLAGS=-fPIC
3.一定要加上--with-protoc=/home/work/protobuf/pc_protobuf/bin/protoc 否则会自动用交叉编译的protoc去生成proto,因为编译过程往往是X86所以会报执行错误
lt-protoc: cannot execute binary file: Exec format error
-