2013-03-08 35 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'