google protobuf在ubuntu上安装使用步骤

来源:互联网 发布:电信网络诈骗手段 编辑:程序博客网 时间:2024/05/21 07:59
1、从github下载protobuff源码。


     https://github.com/google/protobuf

2、安装依赖项:

  * autoconf
  * automake
  * libtool
  * curl (used to download gmock)

执行下面即可:

  $ sudo apt-get install autoconf automake libtool curl


3、产生安装脚本:

     $ ./autogen.sh    ##注意:此处需要翻墙才能成功
   

4、安装:

    $ cd protobuf-master 
    $ ./configure --prefix=/usr/local/protobuf   ##这里是定义安装的位置
    $ make
    $ make check
    $ sudo make install
    $ sudo ldconfig # refresh shared library cache.

5、配置动态链接库路径

     sudo vim /etc/ld.so.conf

      插入:
     /usr/local/protobuf/lib变量。

    sudo vim /etc/profile
 添加
   export PATH=$PATH:/usr/local/protobuf/bin/
   export PKG_CONFIG_PATH=/usr/local/protobuf/lib/pkgconfig/
   保存执行
   source /etc/profile


6、如果要交叉编译的话,比如我要编译hi3518上面用的库时,./configure的时候这样设置
     ./configure --build=i686-pc-linux  --host=arm-hisiv100nptl-linux --with-protoc=protoc --disable-shared --prefix=/home/huang/Desktop/thridparty/protobuf/2.5.0/forHaisi

然后make&&make install 就可以了

写消息文件:msg.proto
package lm; message helloworld {     required int32     id = 1;  // ID       required string    str = 2;  // str      optional int32     opt = 3;  //optional field }
将消息文件msg.proto映射成cpp文件
protoc -I=. --cpp_out=. msg.proto
可以看到生成了
msg.pb.h 和msg.pb.cc

----------------------------------结束------------------------------------------




0 0
原创粉丝点击