目录
- 一、下载源码
- 二、编译安装
- 三、测试
- 四、编译
参考:
1、Protocol Buffers tutorials(C++) 2、google protobuf安装与使用
一、下载源码
github:https://github.com/protocolbuffers/protobuf
二、编译安装
默认安装到/usr/local/lib、/usr/local/include等中,具体看日志
cd protobuf
./configure
make
make check
make install
三、测试
cd example
# 生成c++文件
protoc addressbook.proto --cpp_out=./
执行上面之后变成了:
-rw-rw-r-- 1 nio nio 36227 8月 25 16:27 addressbook.pb.cc # 生成的文件
-rw-rw-r-- 1 nio nio 38670 8月 25 16:27 addressbook.pb.h # 生成的文件
-rw-rw-r-- 1 nio nio 1362 8月 25 13:40 addressbook.proto
四、编译
g++ addressbook.pb.cc add_person.cc -o write `pkg-config --cflags --libs protobuf`
g++ addressbook.pb.cc list_people.cc -o write `pkg-config --cflags --libs protobuf`