安装完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安装遇到的问题以及解决方法(必看篇)全部内容了,希望大家多多支持易采站长站~








