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

我是Thrift的新手.
我想我正确安装了它.我有以下的库:
luckyan315@ubuntu:~/code/thrift-0.8.0/tutorial/cpp$ll /usr/local/lib/

total 11496
drwxr-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.0
USR_DIR    =${HOME}/usr
THRIFT_DIR =${USR_DIR}/${THRIFT_VER}
INCS_DIRS  =-I${USR_DIR}/include -I${THRIFT_DIR}/include/thrift
LIBS_DIRS  =-L${USR_DIR}/lib -L${USR_DIR}/${THRIFT_VER}/lib
CPP_DEFS   =-D=HAVE_CONFIG_H
CPP_OPTS   =-Wall -O2
LIBS       =-lthrift

GEN_SRC    = ../gen-cpp/SharedService.cpp  \
             ../gen-cpp/shared_types.cpp   \
             ../gen-cpp/tutorial_types.cpp \
             ../gen-cpp/Calculator.cpp
GEN_INC    = -I../gen-cpp

default: server client

server: 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/bash
THRIFT_VER=thrift-0.8.0
USR_DIR=${HOME}/usr
THRIFT_DIR=${USR_DIR}/${THRIFT_VER}
export LD_LIBRARY_PATH=${THRIFT_DIR}/lib:${LD_LIBRARY_PATH}
exec $1

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


文章浏览阅读315次。之前用C语言编过链表,这几天突然想用C++编一下链表,搞了大半天才搞出来,所以就赶紧整理一下记录下来,省的万一时间长了找不到代码哈哈。一、链表代码1、Node.h文件代码#pragma onceclass Node{public: int ID; char alph; Node* next; Node(int ID,char alph); ~Node();private:..._if(current->id==id)
文章浏览阅读219次。碰到问题就要记录下来,防止遗忘吧。文章目录一、VS中的命令行参数二、内联函数和宏三、初始化和赋值一、VS中的命令行参数今天在运行代码的时候,碰都了下面的情况: // 解析命令行参数 if (pcl::console::find_argument (argc, argv, "-h") >= 0) { printUsage (argv[0]); return 0; }..._"if (pcl::console::find_argument(argc, argv, "-f") >= 0)怎么输入参数"
文章浏览阅读1.8k次,点赞11次,收藏37次。因为自己对决策树的机制非常的好奇,所以就研究了一下决策树的ID3算法,在这也做一篇笔记记录一下过程。文章目录一、什么是决策树?二、信息增益2.1信息熵2.1.1定义2.1.2演变2.2信息增益三、ID3算法实现四、小结一、什么是决策树?这个问题是我从一开始就有的疑问,什么是决策树?在看了一些资料之后,因为没有看到书上给出具体定义,所以按照我自己的理解决策树就是通过一个个“决策”而构建的一种树状结构,而且决策树的整个处理机制非常类似于我们人类在面临决策问题时的处理机制,这也可能就是其名字的由来。决_c++id3
文章浏览阅读492次。C++ 设计模式之策略模式
文章浏览阅读683次。我也算是个C++的小白,对于C++中的谓语我第一时间就想到了C#中的委托,但两者又不尽相同,所以想写一篇笔记记录一下。文章目录一、什么是谓语?二、使用谓语一、什么是谓语?谓语是一个可调用的表达式,其返回的结果可以作为条件的值,在C++中其实就是向算法传递函数。这和C#中的委托的概念其实是一样的,都是将函数作为参数进行传递。C++标准库中的谓语主要有两类:一元谓语和二元谓语,也就是有的算法只能..._谓语句 c++
文章浏览阅读225次。又看了一遍操作符的东西,感觉之前对操作符的理解还停留在很浅的认知上(仅仅会用哈哈),所以做一下笔记来加深一下印象。文章目录一、为什么会有操作符重载?二、操作符重载作用的对象一、为什么会有操作符重载?如果要回答这个问题,我们其实应该仔细想一下如果没有操作符重载会怎样呢?这其实很容易就联想到了C语言,因为他就没有操作符重载这一说。虽然C语言中没有类class这一概念,但是他有着和类及其相似的结构..._6-6 我的朋友 - c/c++ 操作符重载分数 15作者 海洋饼干叔叔单位 重庆大学实现frie
文章浏览阅读216次。因为之前碰到了很多关于C++上的问题,现在整理并记录一下。文章目录一、引用一、引用在C++中,引用就是给对象起了另一个名字,也就是“对象别名”。感觉和什么东西很相似,仔细一想不就是类型别名“typedef”吗哈哈。它其实是和原对象形成了一种绑定的一种关系,..._vc++6.0报错:returning address of local
文章浏览阅读565次。因为一直好奇预处理器的工作机制,所以就查了查书,做一下自己看完书之后的笔记。文章目录一、预处理器的作用一、预处理器的作用_c语言预处理器作用
文章浏览阅读1.8k次,点赞3次,收藏10次。最近特别查阅了一下关于C++文件的输入/输出的资料,整理了一下就写一下笔记。文章目录一、什么是流二、什么是缓冲区三、代码实现文件IO3.1 使用文件流对象读取数据3.2重定向一、什么是流当前的计算机具有很多种设备,但是无论是哪种设备都要与数据和信息进行打交道,所以这就牵扯到设备与数据之间的I/O操作。而每种设备又有着不同的特性和操作协议,由于过于复杂,所以我们一般是不会和这些通信细节打交道的..._c++ inpath
文章浏览阅读4.8k次,点赞6次,收藏29次。因为要使用到C++的动态链接库,所以就特意网上找了一下资料实现了一下。文章目录一、lib与dll文件二、创建dll文件三、dll隐式链接四、显式链接五、小结一、lib与dll文件之前我一直以为动态链接库就是指dll文件,这也是C#给我造成的一种印象,因为在C#中建立的类库文件都是dll文件,而且只要简单引用就可以了,但是C++却并不是这样的,这可能是因为C#隐藏了一些细节的缘故吧。在C++中共有两种库模式,一种是包含lib和dll两种文件,这种情况下其中的lib文件包含了函数所在的dll文件和dl_c++调用动态链接库
文章浏览阅读973次。因为遇到了一这个操作符的问题,所以记录一下出现的问题*~*。一、问题描述二、产生原因因为也是第一次出现这个问题,所以就到网上查了一些资料和书籍,现在倒也大概理解这个错误出现的原因了。有时候举个例子可能更容易理解为啥会出现这个错误,就拿一本书中的例子来说一下,如下所示:template<class T> class NamedObject { public: NamedObject(std::string& nameVal, const T objectVal) __copy_assign报错
C语言中的单向链表可以解决数组和结构体在使用时的内存连续性问题,同时还能动态地调整长度。本文介绍了单向链表的结构和基本操作,并给出了一个简单的示例代码。
文章浏览阅读2.3k次。区分'0'、"0"、0、''_0和
文章浏览阅读5.8k次,点赞4次,收藏8次。C语言函数指针详解,微剖本质_c语言指针函数
数组指针和指针数组是代码中常见的定义形式。虽然它们的语法类似,但含义完全不同。对于一维数组而言,数组名即为首元素的地址,不需要取址即可赋值给指针。而对于二维数组,数组名代表首行元素的地址,可以看作是一个指针数组,需要使用取址操作。
文章浏览阅读297次。总结刚入门的新同学C语言编程常见的低级错误
文章浏览阅读1.5w次,点赞12次,收藏70次。C语言 数组指针详解_c语言数组指针
文章浏览阅读306次。cJson常用接口总结并测试_用于测试的json接口
本篇文章和大家了解一下C语言中pthread_exit()函数实现终止线程的方法。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。多线程编程中,线程...
本教程操作系统:windows10系统、c99版本、DELL G3电脑。 C语言是一门强大的编程语言,它允许我们对不同的数据类型进行各种运算和操作。但是有时候,我们需要将一个数据类型转换为另一个数据类型。这就是强制类型转