Apache Thrift 学习日记
开始正式学习thrift,今天是第一天,先看看官网文档 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.
按照官网步骤,我们开始thrift之旅
- 下载
- 编译并安装 Apache Thrift compiler
- 学习.thrift 文件
1. 先去下载thrift
http://thrift.apache.org/download
下载的版本是0.10.0
2. 接下来,开始学习如何编译并安装 Apache Thrift compiler
因为使用的是macbook,所以参考的 http://thrift.apache.org/docs/install/os_x 进行环境准备。
使用的boost版本是1.65.1,安装时间比较长,预计30分钟
libevent版本是2.1.8-stable(需要先安装openssl,见 遇到的问题 #1 #2)
最后编译安装Apache Thrift compiler(需要先安装Bison和ant,见 遇到的问题 #3 #4)
安装成功(最后,记得执行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. 总算安装完啦,可以开始学习 thrift 了
遇到的问题
#1. 编译libevent时,提示找不到openssl,这个是因为没有安装openssl(安装完后继续编译libevent),下面给出安装openssl步骤:
- 下载源码 https://www.openssl.org/source/,下载的是1.0.2l
- 执行脚本编译安装
# darwin64-x86_64-cc 这个编译选项可以不加
# 但在执行的过程中提示操作系统是64位的,如果要编译支持64位的库,可以添加这个编译选项
sudo ./Configure darwin64-x86_64-cc --prefix=/usr/local/openssl
make
make install
openssl version
#2. 编译libevent时,安装了openssl,提示找不到 'openssl/ssl.h' 文件
执行configure脚本时,指定寻找路径:
./configure --prefix=/usr/local \
CPPFLAGS="-I/usr/local/openssl/include" \
LDFLAGS="-I/usr/local/openssl/lib"
#3. 安装thrift时,报错: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)
已经安装3.0.4版本
但是安装thrift,仍然报错:Bison version 2.5 or higher must be installed on the system!
经查是使用了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复制到路径下
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),不过先安装的版本是最新版本1.10.1,结果还是不行,看日志发现了这段
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
所以怀疑这个判断版本的逻辑有问题,估计是按字符串比较大小的,所以重新下载了ant 1.9.9 版本,并重新安装了 Apache Thrift compiler,成功!!!
PS: 在解决这个问题的时候,又要回过去解决 "Bison version 2.5 or higher must be installed on the system!" ~~~ TAT
另外,因OSX升级后,/usr/bin sudo都没有写权限了,所以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不存在,这个是mono,c#编译器
cd /usr/local/bin
ln -s -f /Library/Frameworks/Mono.framework/Versions/Current/Commands/mcs
# 然后重新执行configure命令,之后make