歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> CentOS 7下protobuf的源碼編譯安裝

CentOS 7下protobuf的源碼編譯安裝

日期:2017/2/28 13:45:41   编辑:Linux教程

protobuf的github地址:https://github.com/google/protobuf支持多種語言,有多個語言的版本,本文采用的是在CentOS 7下編譯源碼進行安裝。

github上有詳細的安裝說明:https://github.com/google/protobuf/blob/master/src/README.md

1、確定centos7上已經安裝了下面的軟件,或者直接用yum進行更新

autoconf
automake
libtool
curl (used to download gmock)
make
g++
unzip

2、下載源碼包,解壓,編譯安裝

地址:https://github.com/google/protobuf/releases

選擇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這一步會花費比較多的時間

3、設置一下環境變量 /etc/profile

# (動態庫搜索路徑) 程序加載運行期間查找動態鏈接庫時指定除了系統默認路徑之外的其他路徑
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

4、查看版本

protoc --version

之後,對於相同的系統環境,就不需要再編譯了,直接將編譯好的protobuf(目錄:/usr/local/protobuf)分發到其他計算機,設置環境變量即可。

Copyright © Linux教程網 All Rights Reserved