交叉编译protobuf

来源:互联网 发布:如何将一个矩阵对角化 编辑:程序博客网 时间:2024/05/17 07:11

首先编译出本地(x86)版本的protobuf库和编译器(protoc):

我的系统是Ubuntu 12.04,需要改变一下默认安装路径,否则库的路径找不到。

./configure --prefix=/usr

make

make check

make install


为了在ARM平台上使用protobuf,需要交叉编译protobuf库。

只需按照如下方式更改配置:

./configure --prefix=/path/to/dest/dir \

    --host=arm-linux \

    CC=/path/to/arm-linux-gnueabi-gcc \

    CXX=/path/to/arm-linux-gnueabi-g++ \

    --with-protoc=/usr/bin/protoc


使用方法:

一般编译proto文件只需要在x86平台上运行protoc即可

编译ARM上的应用,makefile可以像下面这么写:

/path/to/arm-linux-gnueabi-g++ -g -o main main.cpp some.pb.cc \

    -I. -I/path/to/dest/dir/include -L/path/to/dest/dir/lib \

    -lprotobuf -pthread

其中/path/to/dest/dir就是交叉编译指定的protobuf安装目录。