source : http://hi.baidu.com/guccang/item/9205cbe25c3a1c03570f1dfb
一:本机环境:Ubuntu64位操作系统
uname -a 查询
操作系统:Ubuntu 64位操作系统
交叉编译器:arm-linux-gcc-4.4.3
google protobuf:protobuf-2.4.1
结果,make 时,提示can not find arm-linux-g++
二:本机环境: red hat 32位操作系统
uname -a 查询
操作系统:Linux suowenair 2.6.32-131.0.15.el6.i686 #1 SMP Tue May 10 15:42:28 EDT 2011 i686 i686 i386 GNU/Linux
交叉编译器:arm-linux-gcc-4.4.3
google protobuf: protobuf-2.4.1:
步骤:
第一步:部署protoc.exe文件。
./configure
sudo make
sudo make check
sudo make install
make distclean
make distclean清理生成的Makefile文件,为第二次配置Makefile做准备
make check不会出任何错误提示
第二步:交叉编译
配置makefile文件.
1:./configure --build=i686_pc_linux_gnu --host=arm-linux --with-protoc=protoc --prefix=path_of_arm_linux_lib
--build表示本机环境,如果不清楚,在第一步,./configure时生成makefile时,查看打印信息,或插卡第一步生成的makefile
--host表示编译库的运行的环境,我的是arm架构cpu上运行,所以使用arm-linux,而生成的makefile中--host选项是arm-unknown-linux-gnu
--with-protoc=protoc,此选项的设置,是应为README.txt中所属,交叉编译需要增加此项,如果没有第一步得到部署protoc.exe,会出现错误
错误提示为:protoc找不到。
--prefix=path_of_arm_linux_lib,及设置为交叉编译工具arm-linux-gcc-4.4.3的lib目录的上层目录,--prefix设置的路径,就是make install时,
protobuf的Include,lib目录的拷贝目录。目的在编译时为使用google protobuf标准话的库应用方式(`pkg-config --cflags --libs protobuf`)。
如上配置好configure后,生成Makefile文件,确认CC/CCXX等是否等于arm-linux版本的命令。
我的是 CC=arm-linux-gcc CCXX=arm-linux-g++
2:sudo make
如果未配置--with-protoc=protoc会出错。
如果未执行第一步会出错。提示找不到protoc
其他错误未知。
3:sudo make check
此步骤全部失败,我的提示监测了5个,但5个全部失败。不知道为什么?
但对于arm平台使用libprotobuf.a库没有问题。其他库,为验证。
4:sudo make install
无错误
三:使用库
查看,protobuf的例子。example文件夹,下的Makefile,我们来分析一下:Makfile片段
add_person_cpp: add_person.cc protoc_middleman
pkg-config --cflags protobuf # fails if protobuf is not installed
c++ add_person.cc addressbook.pb.cc -o add_person_cpp `pkg-config --cflags --libs protobuf`
1:使用了 pkg-config --cflags protobuf # fails if protobuf is not installed
来检查是否安装了protobuf
2:使用c++来编译,没有使用g++,
3:使用`pkg-config --cflags --libs protobuf`来表示加载libprotobuf.a库。
而未使用显示配置:-L/path0flib -lprotobuf
注意`pkg-config --cflags --libs protobuf`使用 数字1左边那个按键,而非单引号。
4:那我使用arm-linux编译时,同样使用如上格式,注意三点:
pkg-config --cflags protobuf # fails if protobuf is not installed以防万一
`pkg-config --cflags --libs protobuf`这种形式来加载protobuf的库
arm-linux-c++来编译C++工程。
5:为何要注意上述三点:笔者在使用时遇到了问题。
如使用arm-linux-g++来编译工程但总是提示找不到libprotobuf.a这个库。
按道理来说找不到库原因:有两个
其一是:库所在目录为包含到搜索目录。
其二是:库的版本不对,如arm-linux编译器,连接非arm-linux编译的库。
但两个我都满足了。可任然无法找到libprotobuf.a库文件。
而是用arm-linux-c++就可以。
6:此文,仅为...希望和我遇到同样问题的同学不在纠结了。