thrift 學(xué)習(xí)日記一

Apache Thrift 學(xué)習(xí)日記

開始正式學(xué)習(xí)thrift,今天是第一天,先看看官網(wǎng)文檔 http://thrift.apache.org/

引用一段介紹

The Apache Thrift software framework, for scalable cross-language services development, combines a software stack with a code generation engine to build services that work efficiently and seamlessly between C++, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, Cocoa, JavaScript, Node.js, Smalltalk, OCaml and Delphi and other languages.

按照官網(wǎng)步驟,我們開始thrift之旅

  • 下載
  • 編譯并安裝 Apache Thrift compiler
  • 學(xué)習(xí).thrift 文件

1. 先去下載thrift

http://thrift.apache.org/download
下載的版本是0.10.0

2. 接下來(lái),開始學(xué)習(xí)如何編譯并安裝 Apache Thrift compiler

因?yàn)槭褂玫氖莔acbook,所以參考的 http://thrift.apache.org/docs/install/os_x 進(jìn)行環(huán)境準(zhǔn)備。
使用的boost版本是1.65.1,安裝時(shí)間比較長(zhǎng),預(yù)計(jì)30分鐘
libevent版本是2.1.8-stable(需要先安裝openssl,見 遇到的問(wèn)題 #1 #2)
最后編譯安裝Apache Thrift compiler(需要先安裝Bison和ant,見 遇到的問(wèn)題 #3 #4)
安裝成功(最后,記得執(zhí)行make命令):

thrift 0.10.0

Building Plugin Support ...... : yes
Building C++ Library ......... : yes
Building C (GLib) Library .... : no
Building Java Library ........ : yes
Building C# Library .......... : yes
Building Python Library ...... : yes
Building Ruby Library ........ : no
Building Haxe Library ........ : no
Building Haskell Library ..... : no
Building Perl Library ........ : yes
Building PHP Library ......... : yes
Building Dart Library ........ : no
Building Erlang Library ...... : no
Building Go Library .......... : no
Building D Library ........... : no
Building NodeJS Library ...... : yes
Building Lua Library ......... : no

C++ Library:
   Build TZlibTransport ...... : yes
   Build TNonblockingServer .. : yes
   Build TQTcpServer (Qt4) .... : no
   Build TQTcpServer (Qt5) .... : no

Java Library:
   Using javac ............... : javac
   Using java ................ : java
   Using ant ................. : /usr/local/bin/ant

C# Library:
   Using .NET 3.5 ............ : yes

Python Library:
   Using Python .............. : /usr/bin/python

PHP Library:
   Using php-config .......... :

Perl Library:
   Using Perl ................ : /usr/bin/perl

NodeJS Library:
   Using NodeJS .............. : /usr/local/bin/node
   Using NodeJS version....... : v4.4.4

3. 總算安裝完啦,可以開始學(xué)習(xí) thrift 了

遇到的問(wèn)題

#1. 編譯libevent時(shí),提示找不到openssl,這個(gè)是因?yàn)闆](méi)有安裝openssl(安裝完后繼續(xù)編譯libevent),下面給出安裝openssl步驟:

# darwin64-x86_64-cc 這個(gè)編譯選項(xiàng)可以不加
# 但在執(zhí)行的過(guò)程中提示操作系統(tǒng)是64位的,如果要編譯支持64位的庫(kù),可以添加這個(gè)編譯選項(xiàng)
sudo ./Configure darwin64-x86_64-cc --prefix=/usr/local/openssl
make
make install
openssl version

#2. 編譯libevent時(shí),安裝了openssl,提示找不到 'openssl/ssl.h' 文件
執(zhí)行configure腳本時(shí),指定尋找路徑:

./configure --prefix=/usr/local \
CPPFLAGS="-I/usr/local/openssl/include" \
LDFLAGS="-I/usr/local/openssl/lib"

#3. 安裝thrift時(shí),報(bào)錯(cuò):Bison version 2.5 or higher must be installed on the system!
安裝新版的bison

# 安裝最新 bison
brew install bison

# 安裝完成
$ brew list bison
/usr/local/Cellar/bison/3.0.4/bin/bison
/usr/local/Cellar/bison/3.0.4/bin/yacc
/usr/local/Cellar/bison/3.0.4/lib/liby.a
/usr/local/Cellar/bison/3.0.4/share/aclocal/bison-i18n.m4
/usr/local/Cellar/bison/3.0.4/share/bison/ (23 files)
/usr/local/Cellar/bison/3.0.4/share/doc/ (14 files)
/usr/local/Cellar/bison/3.0.4/share/info/bison.info
/usr/local/Cellar/bison/3.0.4/share/man/ (2 files)
已經(jīng)安裝3.0.4版本

但是安裝thrift,仍然報(bào)錯(cuò):Bison version 2.5 or higher must be installed on the system!

經(jīng)查是使用了xcode自帶的bison,路徑 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/

解決辦法:

# 首先將bison改名
cd /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/
sudo mv bison bison111

# 然后新版本的bison復(fù)制到路徑下
sudo cp /usr/local/Cellar/bison/3.0.4/bin/bison  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/

# 再次安裝thrift,安裝成功。

# 再還原xcode中的bison
cd /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/
sudo rm bison
sudo mv bison111 bison

#4. Building Java Support ... no
參考的這篇文章(http://blog.csdn.net/agul_/article/details/50998187),不過(guò)先安裝的版本是最新版本1.10.1,結(jié)果還是不行,看日志發(fā)現(xiàn)了這段

configure:18828: checking for ant
configure:18846: found /usr/local/bin/ant
configure:18858: result: /usr/local/bin/ant
configure:18867: checking for ant version > 1.7
configure:18874: result: no

所以懷疑這個(gè)判斷版本的邏輯有問(wèn)題,估計(jì)是按字符串比較大小的,所以重新下載了ant 1.9.9 版本,并重新安裝了 Apache Thrift compiler,成功?。?!

PS: 在解決這個(gè)問(wèn)題的時(shí)候,又要回過(guò)去解決 "Bison version 2.5 or higher must be installed on the system!" ~~~ TAT
另外,因OSX升級(jí)后,/usr/bin sudo都沒(méi)有寫權(quán)限了,所以ant改放到/usr/local/bin中

#5. 'boost/utility/enable_if.hpp' 找不到

./configure --prefix=/usr/local/ --with-boost=/usr/local --with-libevent=/usr/local \
CPPFLAGS="-I/usr/local/include" \
LDFLAGS="-I/usr/local/lib"

#6. gmcs不存在,這個(gè)是mono,c#編譯器

cd /usr/local/bin
ln -s -f /Library/Frameworks/Mono.framework/Versions/Current/Commands/mcs

# 然后重新執(zhí)行configure命令,之后make
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容