c – thrift cpp示例代码编译错误

c – thrift cpp示例代码编译错误,第1张

概述我是Thrift的新手. 我想我正确安装了它.我有以下的库: luckyan315@ubuntu:~/code/thrift-0.8.0/tutorial/cpp$ll /usr/local/lib/total 11496drwxr-xr-x 4 root root 4096 Mar 23 19:35 ./drwxr-xr-x 10 root root 4096 Oct 我是Thrift的新手.
我想我正确安装了它.我有以下的库:
luckyan315@ubuntu:~/code/thrift-0.8.0/tutorial/cpp$ll /usr/local/lib/total 11496drwxr-xr-x  4 root root     4096 Mar 23 19:35 ./drwxr-xr-x 10 root root     4096 Oct 12 22:27 ../-rwxr-xr-x  1 root root  4100463 Mar 31 20:26 libthrift-0.8.0.so*-rw-r--r--  1 root root  7256552 Mar 31 20:26 libthrift.a-rwxr-xr-x  1 root root      991 Mar 31 20:26 libthrift.la*lrwxrwxrwx  1 root root       18 Mar 23 19:35 libthrift.so -> libthrift-0.8.0.so*-rwxr-xr-x  1 root root   160727 Mar 31 20:26 libthriftz-0.8.0.so*-rw-r--r--  1 root root   218290 Mar 31 20:26 libthriftz.a-rwxr-xr-x  1 root root      998 Mar 31 20:26 libthriftz.la*lrwxrwxrwx  1 root root       19 Mar 23 19:35 libthriftz.so -> libthriftz-0.8.0.so*

然后我尝试编译cppClIEnt教程,但我有“未定义
参考“错误如下:

luckyan315@ubuntu:~/code/thrift-0.8.0/tutorial/cpp$sudo g++ -DHAVE_NETINET_IN_H -o Server -I/usr/local/include/thrift/ -I/usr/local/boost/include/boost-1_33_1/  -I../gen-cpp -L/usr/local/lib/ -lthrift CppServer.cpp ../gen-cpp/SharedService.cpp ../gen-cpp/shared_types.cpp ../gen-cpp/tutorial_types.cpp ../gen-cpp/Calculator.cpp/tmp/cc7lnwSw.o: In function `main':CppServer.cpp:(.text+0xd1): undefined reference to `apache::thrift::transport::TServerSocket::TServerSocket(int)'CppServer.cpp:(.text+0x15f): undefined reference to `apache::thrift::server::TSimpleServer::serve()'/tmp/cc7lnwSw.o: In function `apache::thrift::server::TSimpleServer::~TSimpleServer()':CppServer.cpp:(.text._ZN6apache6thrift6server13TSimpleServerD2Ev[_ZN6apache6thrift6server13TSimpleServerD5Ev]+0xb): undefined reference to `vtable for apache::thrift::server::TSimpleServer'/tmp/cc7lnwSw.o: In function `apache::thrift::transport::TBufferedTransport::TBufferedTransport(boost::shared_ptr<apache::thrift::transport::TTransport>)':CppServer.cpp:(.text._ZN6apache6thrift9transport18TBufferedTransportC2EN5boost10shared_ptrINS1_10TTransportEEE[_ZN6apache6thrift9transport18TBufferedTransportC5EN5boost10shared_ptrINS1_10TTransportEEE]+0x17): undefined reference to `vtable for apache::thrift::transport::TBufferedTransport'/tmp/cc7lnwSw.o: In function `apache::thrift::server::TSimpleServer::TSimpleServer<apache::thrift::TProcessor>(boost::shared_ptr<apache::thrift::TProcessor> const&,boost::shared_ptr<apache::thrift::transport::TServerTransport> const&,boost::shared_ptr<apache::thrift::transport::TTransportFactory> const&,boost::shared_ptr<apache::thrift::protocol::TProtocolFactory> const&,boost::enable_if<boost::is_convertible<apache::thrift::TProcessor*,apache::thrift::TProcessor*>::type,voID*>::type)':CppServer.cpp:(.text._ZN6apache6thrift6server13TSimpleServerC2INS0_10TProcessorEEERKN5boost10shared_ptrIT_EERKNS6_INS0_9transport16TServerTransportEEERKNS6_INSB_17TTransportFactoryEEERKNS6_INS0_8protocol16TProtocolFactoryEEENS5_9enable_ifINS5_14is_convertibleIPS7_PS4_E4typeEPvE4typeE[_ZN6apache6thrift6server13TSimpleServerC5INS0_10TProcessorEEERKN5boost10shared_ptrIT_EERKNS6_INS0_9transport16TServerTransportEEERKNS6_INSB_17TTransportFactoryEEERKNS6_INS0_8protocol16TProtocolFactoryEEENS5_9enable_ifINS5_14is_convertibleIPS7_PS4_E4typeEPvE4typeE]+0x3a): undefined reference to `vtable for apache::thrift::server::TSimpleServer'/tmp/cc7lnwSw.o: In function `apache::thrift::protocol::TBinaryProtocolT<apache::thrift::transport::TTransport>::writeMessageBegin(std::basic_string<char,std::char_traits<char>,std::allocator<char> > const&,apache::thrift::protocol::TMessageType,int)':CppServer.cpp:(.text._ZN6apache6thrift8protocol16TBinaryProtocolTINS0_9transport10TTransportEE17writeMessageBeginERKSsNS1_12TMessageTypeEi[apache::thrift::protocol::TBinaryProtocolT<apache::thrift::transport::TTransport>::writeMessageBegin(std::basic_string<char,int)]+0x15): undefined reference to `apache::thrift::protocol::TBinaryProtocolT<apache::thrift::transport::TTransport>::VERSION_1'/tmp/cc7lnwSw.o: In function `apache::thrift::protocol::TBinaryProtocolT<apache::thrift::transport::TTransport>::readMessageBegin(std::basic_string<char,std::allocator<char> >&,apache::thrift::protocol::TMessageType&,int&)':CppServer.cpp:(.text._ZN6apache6thrift8protocol16TBinaryProtocolTINS0_9transport10TTransportEE16readMessageBeginERSSRNS1_12TMessageTypeERi[apache::thrift::protocol::TBinaryProtocolT<apache::thrift::transport::TTransport>::readMessageBegin(std::basic_string<char,int&)]+0x33): undefined reference to `apache::thrift::protocol::TBinaryProtocolT<apache::thrift::transport::TTransport>::VERSION_MASK'CppServer.cpp:(.text._ZN6apache6thrift8protocol16TBinaryProtocolTINS0_9transport10TTransportEE16readMessageBeginERSSRNS1_12TMessageTypeERi[apache::thrift::protocol::TBinaryProtocolT<apache::thrift::transport::TTransport>::readMessageBegin(std::basic_string<char,int&)]+0x3d): undefined reference to `apache::thrift::protocol::TBinaryProtocolT<apache::thrift::transport::TTransport>::VERSION_1'/tmp/ccBkDvwC.o: In function `shared::SharedServiceClIEnt::recv_getStruct(shared::SharedStruct&)':SharedService.cpp:(.text+0x6f3): undefined reference to `apache::thrift::TApplicationException::read(apache::thrift::protocol::TProtocol*)'/tmp/ccBkDvwC.o: In function `shared::SharedServiceProcessor::process(boost::shared_ptr<apache::thrift::protocol::TProtocol>,boost::shared_ptr<apache::thrift::protocol::TProtocol>,voID*)':SharedService.cpp:(.text+0xb05): undefined reference to `apache::thrift::TApplicationException::write(apache::thrift::protocol::TProtocol*) const'/tmp/ccBkDvwC.o: In function `shared::SharedServiceProcessor::process_fn(apache::thrift::protocol::TProtocol*,apache::thrift::protocol::TProtocol*,std::basic_string<char,int,voID*)':SharedService.cpp:(.text+0xd87): undefined reference to `apache::thrift::TApplicationException::write(apache::thrift::protocol::TProtocol*) const'/tmp/ccBkDvwC.o: In function `shared::SharedServiceProcessor::process_getStruct(int,voID*)':SharedService.cpp:(.text+0x1409): undefined reference to `apache::thrift::TApplicationException::write(apache::thrift::protocol::TProtocol*) const'/tmp/cclRxoVZ.o: In function `tutorial::CalculatorClIEnt::recv_Ping()':Calculator.cpp:(.text+0x12af): undefined reference to `apache::thrift::TApplicationException::read(apache::thrift::protocol::TProtocol*)'/tmp/cclRxoVZ.o: In function `tutorial::CalculatorClIEnt::recv_add()':Calculator.cpp:(.text+0x173b): undefined reference to `apache::thrift::TApplicationException::read(apache::thrift::protocol::TProtocol*)'/tmp/cclRxoVZ.o: In function `tutorial::CalculatorClIEnt::recv_calculate()':Calculator.cpp:(.text+0x1c7b): undefined reference to `apache::thrift::TApplicationException::read(apache::thrift::protocol::TProtocol*)'/tmp/cclRxoVZ.o: In function `tutorial::CalculatorProcessor::process(boost::shared_ptr<apache::thrift::protocol::TProtocol>,voID*)':Calculator.cpp:(.text+0x227f): undefined reference to `apache::thrift::TApplicationException::write(apache::thrift::protocol::TProtocol*) const'/tmp/cclRxoVZ.o: In function `tutorial::CalculatorProcessor::process_Ping(int,voID*)':Calculator.cpp:(.text+0x298e): undefined reference to `apache::thrift::TApplicationException::write(apache::thrift::protocol::TProtocol*) const'/tmp/cclRxoVZ.o: In function `tutorial::CalculatorProcessor::process_add(int,voID*)':Calculator.cpp:(.text+0x2f9b): undefined reference to `apache::thrift::TApplicationException::write(apache::thrift::protocol::TProtocol*) const'/tmp/cclRxoVZ.o: In function `tutorial::CalculatorProcessor::process_calculate(int,voID*)':Calculator.cpp:(.text+0x3609): undefined reference to `apache::thrift::TApplicationException::write(apache::thrift::protocol::TProtocol*) const'collect2: ld returned 1 exit status
解决方法 -lthrift选项应位于命令行的末尾,位于cpp文件之后.

我已经使用以下makefile在Ubuntu 11.10 / gcc 4.6.1 / boost 1.49上成功编译了示例

THRIFT_VER =thrift-0.8.0USR_DIR    =${HOME}/usrTHRIFT_DIR =${USR_DIR}/${THRIFT_VER}INCS_Dirs  =-I${USR_DIR}/include -I${THRIFT_DIR}/include/thriftliBS_Dirs  =-L${USR_DIR}/lib -L${USR_DIR}/${THRIFT_VER}/libCPP_DEFS   =-D=HAVE_CONfig_HCPP_OPTS   =-Wall -O2liBS       =-lthriftGEN_SRC    = ../gen-cpp/SharedService.cpp  \             ../gen-cpp/shared_types.cpp   \             ../gen-cpp/tutorial_types.cpp \             ../gen-cpp/Calculator.cppGEN_INC    = -I../gen-cppdefault: server clIEntserver: CppServer.cpp    g++ ${CPP_OPTS} ${CPP_DEFS} -o CppServer ${GEN_INC} ${INCS_Dirs} CppServer.cpp ${GEN_SRC} ${liBS_Dirs} ${liBS}clIEnt: CppClIEnt.cpp    g++ ${CPP_OPTS} ${CPP_DEFS} -o CppClIEnt ${GEN_INC} ${INCS_Dirs} CppClIEnt.cpp ${GEN_SRC} ${liBS_Dirs} ${liBS}clean:    $(RM) -r CppClIEnt CppServer

注意在make命令的开头放置选项卡.

我的布局是:

boost 1.49 installed in ${HOME}/usr
boost headers in ${HOME}/usr/include
boost libs in ${HOME}/usr/lib

thrift 0.8.0 installed in ${HOME}/usr/thrift-0.8.0
thrift headers in ${HOME}/usr/thrift-0.8.0/include
thrift libs in ${HOME}/usr/thrift-0.8.0/lib

要运行示例:

#!/bin/bashTHRIFT_VER=thrift-0.8.0USR_DIR=${HOME}/usrTHRIFT_DIR=${USR_DIR}/${THRIFT_VER}export LD_liBRARY_PATH=${THRIFT_DIR}/lib:${LD_liBRARY_PATH}exec 
总结

以上是内存溢出为你收集整理的c – thrift cpp示例代码编译错误全部内容,希望文章能够帮你解决c – thrift cpp示例代码编译错误所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1243826.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存