protobuf在linux环境下c代码生成及测试

来源:互联网 发布:apache 允许目录列表 编辑:程序博客网 时间:2024/06/06 10:02

1.下载

 protobuf-2.5.0.tar.gz源码上传到http://download.csdn.net/download/a493203176/9789098

2.安装

使用tar -zxf protobuf-2.5.0.tar.gz命令解压后得到是protobuf-2.5.0的源码,

cd protobuf-2.5.0 进入目录

假如你希望编译成功后输出的目录为/home/work/protobuf/ 则输入如下两条命令:

 ./configure --prefix=/home/work/protobuf/ 

 make && make install

 编译成功后将export PATH=/home/work/protobuf/bin:$PATH加入到环境变量中

 最后输入 protoc --version命令,如显示libprotoc 2.5.0则安装成功

 

3. 安装protobuf c编译器(需要联网)

sudo apt-get install protobuf-c-compoler没有网情况下  手动下载protobuf c安装包
http://download.csdn.net/download/lk1592/8980395

#  ./configure CXXFLAGS=-I/home/work/protobuf/include LDFLAGS=-L/home/work/protobuf/lib

#  make && make install


4.编译文件

sudo protoc-c student.proto --c_out=./test/说明--c_out=指定生成代码的目录

5. 如果建立一个测试工程

点击打开链接

我测试好的工程:http://download.csdn.net/detail/a493203176/9793853

6. 测试命令(附近有我测试过的例子)

test$ gcc -o test test.c student.pb-c.c protobuf/protobuf-c

 



0 0
原创粉丝点击