Linux下protobuf的編譯與安裝


1.下載源碼

首先,從github上下載protobuf的源碼,地址:https://github.com/google/protobuf,我選擇下載2.5.0版本。

2.編譯protobuf

   將下載的壓縮包解壓縮

unzip protobuf-2.5.0.zip

 

根目錄下沒有configure文件,卻有一個autogen.sh,原來是因為protobuf的編譯方式做了修改,要執行autogen.sh才會生成configure腳本。

但在執行autogen.sh時出錯了,因為google.com被牆了,虛擬機里無法下載gtest,於是手動下載googletest-release-1.5.0.zip,解壓縮后,改名為gtest放在protobuf-2.5.0目錄下 
autgen.sh代碼片段

 1 # Check that gtest is present.  Usually it is already there since the
 2 # directory is set up as an SVN external.
 3 # 判斷是否存在gtest目錄
 4 if test ! -e gtest; then
 5   echo "Google Test not present.  Fetching gtest-1.5.0 from the web..."
 6   #如果目錄不存在則嘗試從google.com下載並解壓縮,如果google被牆則下載失敗
 7   curl http://googletest.googlecode.com/files/gtest-1.5.0.tar.bz2 | tar jx
 8   #將解壓縮后的目錄改名為gtest
 9   mv gtest-1.5.0 gtest
10 fi

googletest1.5.0下載地址:https://github.com/google/googletest

 解壓縮

1 unzip gtest-1.5.0.zip  
2 mv gtest-1.5.0 gtest  

執行protobuf編譯

#執行autogen.sh生成configure
又是一堆的錯誤!!! 運行./autogen.sh時(用於產生configure,) 出現錯誤:

1 linux-lewph:/home/lewph/Projects/System/build_tslib/tslib # ./autogen.sh
2 ./autogen.sh: line 4: autoreconf: command not found

 缺少autoconf這個工具安裝:

1 yum install -y  autoconf

 再次運行./autogen.sh問題又來了:

1 linux-lewph:/home/lewph/Projects/System/build_tslib/tslib # ./autogen.sh
2 Can't exec "aclocal": No such file or directory at /usr/share/autoconf/Autom4te/FileUtils.pm line 326.
3 autoreconf: failed to run aclocal: No such file or directory
1 linux-lewph:/home/lewph/Projects/System/build_tslib/tslib # ./autogen.sh
2 Can't exec "aclocal": No such file or directory at /usr/share/autoconf/Autom4te/FileUtils.pm line 326.
3 autoreconf: failed to run aclocal: No such file or directory   有這個文件,推測,問題出現在exec "aclocal"這里,

用cnf查一下,linux-lewph:/home/lewph/Projects/System/build_tslib/tslib # cnf aclocal

The program 'aclocal' can be found in following packages:
  * automake [ path: /usr/bin/aclocal, repository: zypp (repo-oss) ]
  * automake [ path: /usr/bin/aclocal, repository: zypp (openSUSE 11.2-0) ]

   安裝依賴

1 yum  install automake

原來是要用到automake這個工具!安裝之!完成以后,再運行./autogen.sh .      問題還有!!!:

1 linux-lewph:/home/lewph/Projects/System/build_tslib/tslib # ./autogen.sh
2 configure.ac:25: error: possibly undefined macro: AC_DISABLE_STATIC
3       If this token and others are legitimate, please use m4_pattern_allow.
4       See the Autoconf documentation.
5 configure.ac:26: error: possibly undefined macro: AC_ENABLE_SHARED
6 configure.ac:27: error: possibly undefined macro: AC_LIBTOOL_DLOPEN
7 configure.ac:28: error: possibly undefined macro: AC_PROG_LIBTOOL
8 autoreconf: /usr/bin/autoconf failed with exit status: 1

    這是缺少安裝包libtool-1.5.22.tar.gz 安裝

yum install -y libtool

3.安裝protobuf

1 ./autogen.sh  
2 ./configure
1 make
2 make check
1 sudo make install

 4.成功

    

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM