1、移植PC版本的ProtoBuf的相关文件和可执行程序
1、获取[Protobuf源码](https://github.com/google/protobuf)
2、编译宿主机版本Protobuf软件,因为Protoc-C依赖Protobuf的库文件和头文件(配置编译环境可执行文件)
1)下载完源码后,执行./autogen.sh
2)生成一个configure可执行程序
3)执行./configure --prefix=/homelisx/usr/local/protobuf没有错误输出,生成Makefile文件
如出现以下错误:
configure.ac:30: error: possibly undefined macro: AC_PROG_LIBTOOL
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
autoreconf: /usr/bin/autoconf failed with exit status: 1
或者
hecking whether to enable maintainer-specific portions of Makefiles... yes
configure: error: cannot find install-sh, install.sh, or shtool in "." "./.." "./../.."
解决办法:
检查环境路径以及安装libtool,
sudo apt-get install libtool
4)然后执行make && sudo make install 会生成的可执行程序、头文件、lib库在默认的路径下面/usr/local/protobuf
5)可执行程序protoc用于将规则序列化文件.pro生成源代码供使用者使用
2、移植PC版本的Protobuf-C文件
1、下载[Protobuf-C源码](https://github.com/protobuf-c/protobuf-c.git)
2、编译PC版本的Protobuf-c文件
注意,编译此执行文件需要ProtoBuf中的库支持
1)执行./autogen.sh
2)执行./configure的时候会出现
(configure: error: required protobuf header file not found)这个错误,
需要导入刚才编译好的protobu的生成文件的配置文件pkgconfig的路径信息。
解决办法:
export PKG_CONFIG_PATH=/home/lisx/usr/local/protobuf/lib/pkgconfig
然后在执行./configure --prefix=/home/lisx/usr/local/protobuf,即可生成Makefile文件
3)
执行make
sudo make install
就可以生成protoc-c、头文件、库文件(路径/home/lisx/usr/local/protobuf)
其中protoc-c用于将.pro文件生成.c .h文件,供应用使用。
XXX.proto文件书写规则
https://github.com/protobuf-c/protobuf-c/wiki/Examples
如:
./protoc-c esp_hosted_config.proto --c_out=.
生成的
esp_hosted_config.pb-c.c
esp_hosted_config.pb-c.h
两个文件即为序列化文件
3、移植mips版本的Protobuf-C可执行文件
1、mips版本不需要protoc-c程序,因为生成代码和编译在PC上编译,板子上只是运行应用程序。
2、同一份protoc-c代码,然后make clean一下
3、导入mips版本的gcc编译器的环境变量
4、配置编译信息
(如果configure后不加参数即表示是在本机编译可执行程序,如果在后加平台参数即表示编译在某平台可执行文件)
如:我编译mips架构的可执行文件:
./configure --host=mips-linux CC=mips-linux-gnu-gcc-5.4.0 CXX=mips-linux-gnu-g++ --prefix=/home/lisx/protobuf
其中相关的--host后面是平台名称mips-xxx是你arm编译器的相关名字
--prefix配置的是你生成文件的路径
CC是gcc
CXX是g++
5、make && make install 即可在你指定的文件夹中看到生成的文件