protobuf
Protobuf全称是Google Protocol Buffer, 是谷歌公司提供的用于通信的结构化数据存储方式。
编译protobuf库
由于在编写完protobuf文件后,文件对应产生的.h文件和.cc文件还会依赖protobuf的头文件和库文件,因此需要编译protobuf库。
windows平台编译
准备工具:
- cmake
- visual studio
编译release版本:
这里选择使用CMake编译Protobuf工程,由于不需要使用Tests,就可以先把这个勾去掉。
然后就在build目录下产生了VS的工程项,使用VS Stuio进行编译即可。
编译产物
在protobuf目录下install文件夹中,包括
- bin下的可执行文件
- include头文件
- lib库
MacOSX
准备
- homebrew
- cmake
- xcode
编译准备
- brew install automake
- brew install libtool
- ./autogen.sh
编译
- ./configure
- cmake check
- make
- make install
编译产物
lib库
生成proto文件
简单编写一个proto文件 example.proto
syntax = "proto3";
message Account {
//account
uint64 account = 1;
//name
string name = 2;
//passwd
string