Thrift安装遇到的问题及解决方案

1. 必须安装boost。最新的稳定版是1.48.0。

1.1.先下载:http://sourceforge.net/projects/boost/files/boost/1.48.0/
    选择tar.gz包,

    下载后我解压到了/usr/local/boost_1_48下:tar zxvf boost1.48.0 -C /usr/local/boost_1_48

1.2.安装过程和以前的老版本有些不同,看自带软件包里的index.html就可以了:

    主要内容涉及到安装的就2步,很简单,进入一级目录:

    $ ./bootstrap.sh //默认安装到/usr/local/include/boost 和/usr/local/lib下
    $ ./b2 install

1.3接下来设置环境变量自动导入:

   先用vim创建文件:/etc/profile.d/boost.sh,(若不能执行的话使用chmod a+x boost.sh设置执行权限),

   内容为:

#!/bin/sh
#boost settings
BOOST_ROOT=/opt/boost_1_48
BOOST_INCLUDE=/usr/local/include/boost
BOOST_LIB=/usr/local/lib
export BOOST_ROOT BOOST_INCLUDE BOOST_LIB

注意:
linux程序运行时加载共享库出现的错误:
"error while loading shared libraries: xxxx: cannot open shared object file: No such file or directory"
解决步骤:
1、使用find命令查找缺失的xxxx共享库文件所在位置。参考:#find 目录 -name "xxxx*"
2、将找到的目录位置写入 /etc/ld.so.conf 配置文件,这个文件记录了编译时使用的动态链接库的路径。
3、然后使用ldconfig命令,使配置生效。

2. 安装libevent(选择noblokingserver必须安装libevent,如果出现noblokingserver相关的错误就是没有安装libevent)。

  我安装的版本是最新的libevent1.4.13:

wget http://monkey.org/~provos/libevent-1.4.13-stable.tar.gz

tar xvzf libevent-1.4.13-stable.tar.gz

cd libevent-1.4.13-stable

./configure && make

make install

3. 接下来就是安装thrift,我下载的是最新的thrift0.8.0版本,进入thrift0.8.0目录:

   因为我只需要编译cpp,用以下命令:(编译选项可以参考http://www.coder4.com/archives/2110):

. /configure  --with-cpp  --with-boost  --without-python  --without-csharp --without-java --without-erlang --without-perl --without-php --without-php_extension --without-ruby --without-haskell --without-go
 
#make
make
 
#install
make  install

   如果还需要编译java或者别的语言,还需要提前安装别的包,具体参考http://wiki.apache.org/thrift/ThriftRequirements:

  • C++
    • Boost 1.33.1+
    • libevent (optional, to build the nonblocking server)
    • zlib (optional)
  • Java
    • Java 1.5+
    • Apache Ant
    • Apache Ivy (recommended)
    • Apache Commons Lang (recommended)
    • SLF4J
  • C#: Mono 1.2.4+ (and pkg-config to detect it) or Visual Studio 2005+
  • Python 2.4+ (including header files for extension modules)
  • PHP 5.0+ (optionally including header files for extension modules)
  • Ruby 1.8+ (including header files for extension modules)
  • Erlang R12 (R11 works but not recommended)
  • Perl 5
    • Bit::Vector
    • Class::Accessor

安装完thrift先试验一下。进入thrift下的tutorial,编译给出的例子:

   thrift -r --gen cpp tutorial.thrift

会在gen-cpp目录下生成一些文件。然后进入CPP目录,进行编译:

   make

有可能遇到错误,提示: hton* declarations will not be visible to the compiler。这是thrift的一个bug,可能有的版本没有该错误,但是我安装的这个版本有。解决的办法是:

使用g++编译时加入 -DHAVE_NETINET_IN_H

这样可以使预处理器include进 netinet/in.h in thrift/protocol/TPrototol.h, 这样 hton* declarations will be visible to the compiler.

下面是一个老外对这个bug的说明:

TProtocol.h has the following lines which cause the compiler error when HAVE_NETINET_IN_H is not defined.

#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif

This might be a bug in the Thrift configure script which somehow skips the define.

针对上面的那个例子,修改CPP文件夹里的Makefile,在编译行加入相应的参数:

 g++ -DHAVE_NETINET_IN_H -o CppServer -I${THRIFT_DIR} -I${BOOST_DIR}  -I../gen-cpp -L${LIB_DIR} -lthrift CppServer.cpp ${GEN_SRC}

 再进行make,得到两个可执行文件,先执行CppServer,再启动CppClient。

                                 到此,thrift安装完毕。

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值