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目錄,進行編譯:
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安裝完畢。
以上就是小編為大家帶來的thrift安裝遇到的問題以及解決方法(必看篇)全部內容了,希望大家多多支持VEVB武林網~
新聞熱點
疑難解答
圖片精選