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.gztar xvzf libevent-1.4.13-stable.tar.gzcd libevent-1.4.13-stable./configure && makemake 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 #makemake #installmake install
如果还需要编译Java或者别的语言,还需要提前安装别的包,具体参考http://wiki.apache.org/thrift/ThriftRequirements:
C++Boost 1.33.1+libevent (optional, to build the nonblocking server)zlib (optional)JavaJava 1.5+Apache AntApache Ivy (recommended)Apache Commons Lang (recommended)SLF4JC#: 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 5Bit::VectorClass::Accessor
安装完thrift先试验一下。进入thrift下的tutorial,编译给出的例子:
thrift -r --gen cpp tutorial.thrift,
会在gen-cpp目录下生成一些文件。然后进入CPP目录,进行编译:
新闻热点
疑难解答