使用brew安装
使用brew install thrift会安装最新版本的thrift,目前是0.9。
手动安装
安装基本组件
1、安装BOOST
./bootstrap.sh
sudo ./b2 threading=multi address-model=64 variant=release stage install
2、安装 libevent
./configure --prefix=/usr/local
make
sudo make install
3、针对不同语言,需要安装不同的组件
比如java库,需要安装java、ant,否则在安装thrift时,将不会安装该语言的代码生成器。
包括BOOST和libevent,均可以使用brew进行安装。
4、安装 Apache Thrift
./configure --prefix=/usr/local/ --with-boost=/usr/local --with-libevent=/usr/local
有些不需要的lib不用编译,避免报错。
./configure --prefix=/usr/local/ --with-boost=/usr/local --with-libevent=/usr/local --without-erlang --without-ruby --without-php
上面剔除了erlang、ruby、php等语言。
make
sudo make install
thrift -version 可以查看安装是否成功和版本。
安装8的时候会遇到如下问题,并按如下解决:
Osx 10.9 是比较新的系统, 从这个版本开始, 系统默认编译器从GCC 改为 Clang(GCC -v 一下, 给的是clang 的提示).
Thrift 0.8 代码相对又比较老, 在新的编译器上遇到了下列一些问题.
问题1 :
多个源码文件报错 # include <tr1/functional>, file not found, 改为 # include <boost/tr1/functional.hpp> 解决.
需要修改以下文件:
- lib/cpp/src/concurrency/ThreadManager.h line:24
- lib/cpp/src/async/TAsyncChannel.h line:23
- lib/cpp/src/async/TAsyncChannel.cpp line:21
- lib/cpp/src/async/TAsyncProcessor.h line:23
- lib/cpp/src/async/TAsyncBufferProcessor.h line:23
原因: 在我试验的环境下, 此头文件有后缀名/usr/local/include/boost/ tr1/functional.hpp
问题2:
cpp 测试代码 test/Benchmark.cpp 编译失败, shared_ptr ambigous , 用 boost::shared_ptr 替换 shared_ptr,
错误消失.
原因: Clang 支持 C++ 11, 其 标准库自带 shared_ptr(std::shared_ptr, 参考 http://zh.cppreference.com/w/cpp/memory/shared_ptr)
故需显式指定名字空间.