文章出處
文章列表
1、protobuf是google公司提出的數據存儲格式,詳細介紹可以參考:https://code.google.com/p/protobuf/
2、下載最新的protobuf,下載地址:https://code.google.com/p/protobuf/downloads/list
3、下載protobuf2.5.o版本,protobuf-2.5.0.tar.gz解壓并進行安裝。
解壓:tar xvf protobuf-2.5.0.tar.gz
安裝步驟:(1)./configure (2)make (3)make check (4)make install
注意:安裝成功后,將它的bin和lib目錄分別加入到PATH和LD_LIBRARY_PATH環境變量,以方便直接調用。
通常建議安裝到/usr/local目錄下,執行configure時,指定--prefix=/usr/local/protobuf即可
設置環境變量過程:編輯/etc/profile,在文件末尾添加:
export PATH=$PATH:/usr/local/protobuf/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/protobuf/lib
4、測試例子:
創建一個.proto文件,文件為:x.proto
1 package x; 2 message person 3 { 4 required string name = 1; 5 required int32 id = 2; 6 optional string email = 3; 7 }
編譯成目標語言: protoc -I=src_dir --cpp_out=dst_dir $src_dir/addressbook.proto
5、C++語言編譯命令如下:
g++ -Wall -g ./dst_dir/x.pb.cc x.cpp -o x -I. -I/usr/local/protobuf/include -L/usr/local/protobuf/lib -lprotobuf -pthread
參考:
http://www.ibm.com/developerworks/cn/linux/l-cn-gpb/
http://www.hadoopor.com/thread-1837-1-1.html
文章列表
全站熱搜