2013-03-08 36 views
4

我想编译一段代码创建一个TNonblockingServer,我得到以下编译错误。任何想法有什么不对?Apache thrift未定义的参考apache :: thrift :: server :: TNonblockingServer

something_server.cpp:(.text+0x1ad): undefined reference to `apache::thrift::server::TNonblockingServer::serve()' 
something_server.cpp:(.text+0x1c1): undefined reference to `apache::thrift::server::TNonblockingServer::~TNonblockingServer()' 
something_server.cpp:(.text+0x280): undefined reference to `apache::thrift::server::TNonblockingServer::~TNonblockingServer()' 

我在安装节俭时执行了这里列出的步骤。 http://thrift.apache.org/docs/install/os_x/

这里是我的makefile

GEN_SRC := Something.cpp something_constants.cpp something_types.cpp 
GEN_OBJ := $(patsubst %.cpp,%.o, $(GEN_SRC)) 

THRIFT_DIR := /usr/local/include/thrift 
BOOST_DIR := /usr/local/include 

INC := -I$(THRIFT_DIR) -I$(BOOST_DIR) 

.PHONY: all clean 

all: something_server something_client 

%.o: %.cpp 
    $(CXX) -Wall -DHAVE_INTTYPES_H -DHAVE_NETINET_IN_H $(INC) -c $< -o [email protected] 

something_server: something_server.o $(GEN_OBJ) 
    $(CXX) $^ -o [email protected] -L/usr/local/lib -lthrift 

something_client: something_client.o $(GEN_OBJ) 
    $(CXX) $^ -o [email protected] -L/usr/local/lib -lthrift 

clean: 
    $(RM) *.o something_server something_client 
+0

由于未链接库,这看起来像一个普通的链接问题。你如何编译和链接? – comocomocomocomo 2013-03-08 07:45:38

+0

我编辑了这个问题并添加了我的makefile。 – 2013-03-08 07:47:11

+8

尝试添加-lthriftnb库到您的make文件 – Dmitry 2013-04-13 15:58:56

回答

1

正如梅德指出的那样,如果我们增加-lthriftnb到编译命令,它解决了这个问题。这些缺少的参考文献可在libthriftnb.so中找到。该文件具有对libevent的引用。所以我不得不包含-levent来编译命令。没有-levent链接器会生成多个错误消息。一些消息如下 -

/usr/local/lib/libthriftnb.so: undefined reference to `event_set' 
/usr/local/lib/libthriftnb.so: undefined reference to `evbuffer_new' 
/usr/local/lib/libthriftnb.so: undefined reference to `evhttp_free' 
. 
. 
. 
. 
/usr/local/lib/libthriftnb.so: undefined reference to `event_del'