Thrift安装笔记
当前开发必须使用trhift 0.8.0版本,与mtthrift基于的版本保持一致,虽然最新版本已经修正了一些bug,但是新版容易出现和mtthrift编译不兼容的问题,例如当前最新的0.10.0通过IDL生成的java文件使用mtthrift时无法编译通过,提示错误:org.apache.thrift.TBaseAsyncProcessor无法找到。
安装步骤
安装boost
从http://www.boost.org/下载最新的boost源码压缩包,解压后执行下面命令:
./bootstrap.shsudo ./b2 threading=multi address-model=64 variant=release stage install |
安装libevent
由于libevent的编译安装依赖openssl,而mac默认安装了openssl但是没有安装对应的include头文件和lib库,故这里使用homebrew(参考https://brew.sh/index_zh-cn.html)来安装最新的openssl,执行以下命令:
brew install opensslbrew link openssl --froceln -s /usr/local/opt/openssl/bin/openssl /usr/local/bin/opensslln -s /usr/local/opt/openssl/include/openssl /usr/local/include/opensslln -s /usr/local/opt/openssl/lib/libssl.a /usr/local/lib/libssl.aln -s /usr/local/opt/openssl/lib/libcrypto.a /usr/local/lib/libcrypto.a |
由于brew默认将openssl安装到/usr/local/opt/openssl目录,不在默认的系统目录,导致编译libevent时仍不能找到openssl,故通过ln命令在系统目录建立openssl相关的软连接从而编译libevent时方便找到openssl。
然后,从http://libevent.org/下载最新的libevent源码压缩包,解压后执行下面命令:
./configure --prefix=/usr/localmakesudo make install |
安装thrift
从http://thrift.apache.org/下载0.8.0版本的thrift代码压缩包。由于默认0.8.0版本的源码在mac上编译有问题(0.10.0已解决),故需要进行以下简单修正:
1.多个源文件编译时报错#include <tr1/functional>, file not found,需要将#include <tr1/functional>改为#include <boost/tr1/functional.hpp>,需要修改的文件如下:
{thrift目录}/lib/cpp/src/concurrency/ThreadManager.h line:24
{thrift目录}/lib/cpp/src/async/TAsyncChannel.h line:23
{thrift目录}/lib/cpp/src/async/TAsyncChannel.cpp line:21
{thrift目录}/lib/cpp/src/async/TAsyncProcessor.h line:23
{thrift目录}/lib/cpp/src/async/TAsyncBufferProcessor.h line:23
2. cpp测试文件代码test/Benchmark.cpp编译时报错:shared_ptr ambigous,用 boost::shared_ptr 替换 shared_ptr,需要修改的文件如下:
{thrift目录}/lib/cpp/test/Benchmark.cpp
3. 默认编译ruby和php相关模块时也会出现编译错误,而当前项目不需要使用ruby和php,故配置代码时使用--without-ruby和--without-php排除ruby和php相关的编译(当前情况不需要修改源码文件,只需要给configure添加命令行选项)
最终执行以下命令完成编译安装:
./configure --prefix=/usr/local/ --with-boost=/usr/local --with-libevent=/usr/local --without-ruby --without-phpmakesudo make install |
最有执行命令"thrift -version"可以看到正常输出“Thrift version 0.8.0”,表明安装成功。

浙公网安备 33010602011771号