Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1683552
  • 博文数量: 347
  • 博客积分: 9328
  • 博客等级: 中将
  • 技术积分: 2680
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-29 23:45
文章分类

全部博文(347)

文章存档

2016年(1)

2013年(4)

2012年(207)

2011年(85)

2010年(50)

分类: C/C++

2012-12-11 10:35:37

原文:http://blog.csdn.net/yuezhiren/article/details/8094755

文章记录了交叉编译google protobuf 的整个过程。

build 环境: 

            OS/hardware-platform :  Linux ubuntu 3.2.0-32-generic-pae #51-Ubuntu SMP Wed Sep 26 21:54:23 UTC 2012 i686 i686 i386 GNU/Linux

            CROSS_COMPILER    :  gcc version 4.3.2 (Sourcery G++ Lite 2008q3-72)   【已经设置了PATH 】

Target 环境: 

           OS/hardware-platform  :     Linux at91.linux 2.6.30 #2 Wed Oct 10 23:33:55 CST 2012 armv5tejl GNU/Linux


1.  从官网下载最新的 protobuf,    ,目前最新的是 2.4.1

     

  1. tar -xvjf  protobuf-2.4.1.tar.bz2      

     【tar tips: 首个字符 x 是必须的 , 代表解压;    v 代表 verbose, 代表输出所有解压文件信息 ;  j 代表 bzip2 ,即 bz2格式, 有时候也用z,  z代表 gzip ; f 代表使用的是归档文件   】


2 . build protobuf  , 有以下需要注意的地方:

     <1>  protobuf 中的 README.txt 提到了在交叉编译 protobuf 时需要加上选项  --with-protoc , 例如, 如果在本地已经安装过 protobuf, 则 configure 的配置选项:


  1. ./configure --with-protoc=protoc 【。。。。。。。。。其他配置选项】  

需要注意的是 protoc 的版本必须要当前protobuf版本一致。

我的做法是: 先再本地编译/安装protobuf,然后再按照上面的样式指定

  1. ./confgure  
  2. make  
  3. sudo make install  
  4. make distclean  
  5. ./configure --with-protoc=protoc  【。。。。。。。。。其他配置选项】  

详细内容猛戳 :


<2> 启用 configure 的交叉编译功能

重点在于如何通过命令行启用 configure 的交叉编译功能,这些命令行又是如何在起作用。需要注意的是,

2.4.1所使用的 autoconf 是 2.65, 随着升级, autoconf 发生了很多变化, 具体解释请猛戳 :

重点的命令行如下 :

--build 用于描述编译环境, 在我的环境中设置为 i686-pc-linux (x86_64 , ubuntu)


--host 用于描述目标程序包的运行环境,当 --host 与 --build 的值不同时,启用交叉编译模式。 

在我的环境中设置为 arm-linux。 【由于历史原因,当设置 --host 时,一定需要设置 --build】


--target 用于配置交叉编译环境(很少用到),默认与 --host 相同。 比如我的host 设置成为 arm-linux ,

那么使用的 arm-linux-gcc 编译。

【还没有搞清楚详细的交叉编译配置功能,暂时就我的机器来看, configure 是这么做的】


  这么一来我的机器的 configure 命令行则为 :

  1. ./configure --build=i686-pc-linux  --host=arm-linux --with-protoc=protoc  

注1 :  

注2 : 

注3  :   


<3> 其他 , 包括设置安装路径, 设置静态库

   为了方便开发, 我使用的是 nfs root 【详细猛戳 :   】 , 所以只需要把 protobuf 安装到本地目录下即可,另外由于静态链接会提升运行性能,所以使用编译静态库,整个 configure 则为 :

  1. ./configure --build=i686-pc-linux  --host=arm-linux --with-protoc=protoc --disable-shared --prefix=/home/marmot/sample_fs/rootfs/usr  

      然后 

      make

      sudo make install 即可


3 .  在嵌入式系统中使用 protobuf

       protobuf-lite 是 专门为嵌入式系统优化的runtime,牺牲了一些特性,换来了一些相对小的库以及不错的性能.

      要使用protobuf-lite ,需要在所定义的proto文件中需要声明:

       

  1. option optimize_for = LITE_RUNTIME;  


帮助猛戳  :  protobuf language guide 


还有一个问题没有搞定:

     编译armv5版本的protobuf,编译器默认 armv4T


[ 根据 automake 中关于  中的说明, 再 configure 预定义CFLAGS CXXFLAGS一下就可以使用了 ]

  1. ./configure --build=i686-pc-linux  --host=arm-linux --with-protoc=protoc --disable-shared --prefix=/home/marmot/Downloads/testinstall CFLAGS=' -march=armv5 '  CXXFLAGS=' -march=armv5  '  
阅读(3224) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~