1. 确认安装依赖库:automake ,autoconf ,libtool
2. 下载 protobuf 安装文件,protobuf-cpp-3.5.0.tar.gz ,
解压,
./configure
make
make check
make install
【默认安装路径:/usr/local/】
3. 安装完添加环境变量, vi /etc/profile 末尾添加
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
二、 protobuf-c 的安装
1.确认安装依赖: protobuf
2. 需在github上下载protobuf-c protobuf-c-master.zip
解压
./autogen.sh
./configure
make
make install
【默认安装路径:/usr/local/】
三、 protobuf 交叉编译
1、打包下载protobuf-c,地址:https://github.com/protobuf-c/protobuf-c
2、解压后得到protobuf-c-master文件夹,进入该文件夹执行如下命令
3、./autogen.sh
4、./configure --host=arm-linux CC=arm-none-linux-gnueabi-gcc CXX=arm-none-linux-gnueabi-g++ --disable-protoc --prefix=/usr/local/protobuf-c-arm
CC=指定gcc编译器,CXX=指定g++编译器,--disable-protoc 不使用protoc(因为它是C++版本,此处只用它生成两个文件,编译处用不到,除非在arm机器上编译protoc代码才会用到),--prefix=指定安装路径
5、make
6、等待完成,最终会在protobuf-c-master /protobuf-c/.libs目录下生成.so动态库
四、程序编译
[root@localhost test]# arm-none-linux-gnueabi-gcc test.pb-c.c test.c -o main -I/头文件路径 -L/库路径 -lprotobuf-c