Centos6.4下安裝protobuf及簡單使用

一、protobuf是google公司提出的數據存儲格式,詳細介紹能夠參考:https://code.google.com/p/protobuf/ html

二、下載最新的protobuf,下載地址:https://code.google.com/p/protobuf/downloads/list linux

三、下載protobuf2.5.o版本,protobuf-2.5.0.tar.gz解壓並進行安裝。 oop

解壓:tar xvf protobuf-2.5.0.tar.gz 測試

安裝步驟:(1)./configure (2)make (3)make check (4)make install ui

注意:安裝成功後,將它的bin和lib目錄分別加入到PATH和LD_LIBRARY_PATH環境變量,以方便直接調用。 google

一般建議安裝到/usr/local目錄下,執行configure時,指定--prefix=/usr/local/protobuf便可                spa

設置環境變量過程:編輯/etc/profile,在文件末尾添加: code

export PATH=$PATH:/usr/local/protobuf/bin export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/protobuf/lib

四、測試例子: htm

建立一個.proto文件,文件爲:x.proto hadoop

複製代碼
 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 
五、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
相關文章
相關標籤/搜索