protobuf的github地址:https://github.com/google/protobuf支持多種語言,有多個語言的版本,本文采用的是在CentOS 7下編譯源碼進行安裝。linux
github上有詳細的安裝說明:https://github.com/google/protobuf/blob/master/src/README.mdgit
一、肯定centos7上已經安裝了下面的軟件,或者直接用yum進行更新github
autoconf automake libtool curl (used to download gmock) make g++ unzip
二、下載源碼包,解壓,編譯安裝centos
地址:https://github.com/google/protobuf/releasescurl
選擇Source code (tar.gz)下載測試
tar -zxvf protobuf-3.1.0.tar.gz -C /usr/local/ cd protobuf-3.1.0/ # 若是使用的不是源碼,而是release版本 (已經包含gmock和configure腳本),能夠略過這一步 ./autogen.sh # 指定安裝路徑 ./configure --prefix=/usr/local/protobuf #編譯 make # 測試,這一步很耗時間 make check make install # refresh shared library cache. ldconfig
注意make check這一步會花費比較多的時間google
三、設置一下環境變量 /etc/profileurl
# (動態庫搜索路徑) 程序加載運行期間查找動態連接庫時指定除了系統默認路徑以外的其餘路徑 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/protobuf/lib # (靜態庫搜索路徑) 程序編譯期間查找動態連接庫時指定查找共享庫的路徑 export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/protobuf/lib export PATH=$PATH:/usr/local/protobuf/bin
四、查看版本centos7
protoc --version
以後,對於相同的系統環境,就不須要再編譯了,直接將編譯好的protobuf(目錄:/usr/local/protobuf)分發到其餘計算機,設置環境變量便可code