[url]http://wiki.apache.org/thrift/ThriftInstallation[/url]
[size=x-large]Basic requirements[/size]
A relatively POSIX-compliant *NIX system
Cygwin or MinGW can be used on Windows
g++ 3.3.5+
boost 1.33.1+ (1.34.0 for building all tests)
Runtime libraries for lex and yacc might be needed for the compiler.
[size=x-large]一、安装依赖[/size]
yum install automake libtool flex bison pkgconfig gcc-c++ boost-devel libevent-devel zlib-devel python-devel ruby-devel
[size=x-large]二、安装thrift[/size]
wget http://archive.apache.org/dist/thrift/0.9.0/thrift-0.9.0.tar.gz
tar zxvf thrift-0.9.0
cd thrift-0.9.0
首先运行根目录下的 $ ./bootstrap.sh,用于生成configure脚本
如果下载的直接是一个tarball,则跳过此步骤,直接运行软件根目录下的configure脚本
./bootstrap.sh
./configure
make
make install
[size=large]验证[/size]
查看当前版本
$ thrift -version
Thrift version 0.9.0
输出信息和安装的版本一致,说明thrift安装成功
Maven artifact
org.apache.thrift
libthrift
0.9.0
[size=X-large]三、安装fb303[/size]
Facebook Bassline (included in thrift/contrib/fb303/)
fb303 r697294 or later is required.
(已经包含在Thrift中了,重新编译一下fb303就可以)
cd ./contrib/fb303/
./bootstrap.sh
./configure
make
make install
安装完Thirft后,记得运行一下它提供的example,看是否安装成功。
验证:
cd ./thrift-0.9.0/tutorial
thrift -r -gen cpp tutorial.thrift // -r对其中include的文件也生成服务代码 -gen是生成服务代码的语言
cd cpp
make
运行完之后会在当前目录看到一个gen-cpp目录,其中就是thrfit命令生成的代码。这时你cd到tutorial/cpp目录,运行make,生成相应的CppServer与CppClient程式。
此时你可以分别运行CppServer和CppClient,让它们通信。