2012-03-31 10 views
6

मैं थ्रिफ्ट के लिए नया हूं। मुझे लगता है कि मैंने इसे सही तरीके से स्थापित किया है। मैं folowing libs है:ट्र्रिफ्ट सीपीपी नमूना कोड संकलन त्रुटि

[email protected]:~/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 ट्यूटोरियल संकलित करने के लिए tryed लेकिन मैं "अपरिभाषित संदर्भ" त्रुटियों के रूप में निम्नानुसार है:

[email protected]:~/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, std::char_traits<char>, std::allocator<char> > const&, apache::thrift::protocol::TMessageType, 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::char_traits<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, std::char_traits<char>, std::allocator<char> >&, apache::thrift::protocol::TMessageType&, 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, std::char_traits<char>, std::allocator<char> >&, apache::thrift::protocol::TMessageType&, 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, std::char_traits<char>, std::allocator<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, apache::thrift::protocol::TProtocol*, apache::thrift::protocol::TProtocol*, 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>, 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, apache::thrift::protocol::TProtocol*, apache::thrift::protocol::TProtocol*, 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, apache::thrift::protocol::TProtocol*, apache::thrift::protocol::TProtocol*, 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, apache::thrift::protocol::TProtocol*, apache::thrift::protocol::TProtocol*, void*)': 
Calculator.cpp:(.text+0x3609): undefined reference to `apache::thrift::TApplicationException::write(apache::thrift::protocol::TProtocol*) const' 
collect2: ld returned 1 exit status 
+0

मेरे आदेश है: sudo जी ++ -DHAVE_NETINET_IN_H -ओ सर्वर मैं/usr/स्थानीय/शामिल/थ्रिफ्ट/-आई/यूएसआर/स्थानीय/बूस्ट/शामिल/बूस्ट -1_33_1/-आई ../ 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 –

+0

आप रूट के रूप में g ++ क्यों कॉल कर रहे हैं? बिना प्रयास करें, लेकिन ldconfig (रूट के रूप में) चलाने का प्रयास करें पहले –

उत्तर

8

-lthrift विकल्प के अंत में होना चाहिए सीपीपी फाइलों के बाद कमांड लाइन।

मैं सफलतापूर्वक उबंटू 11.10/जीसीसी 4.6.1 पर नमूना संकलित किया है/निम्नलिखित makefile साथ 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 

कर आदेशों की शुरुआत में टैब डाल करने के लिए ध्यान रखना।

मेरे लेआउट है:

बढ़ावा 1.49 में स्थापित $ {गृह}/usr
$ {गृह} में बढ़ावा हेडर/usr/$ {गृह}/usr/lib में
बढ़ावा libs शामिल

बचत 0.8.0 में स्थापित $ {गृह} /usr/thrift-0.8.0
$ में बचत हेडर {गृह} /usr/thrift-0.8.0/include
बचत libs $ में {} गृह /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 
+0

बिल्कुल सही !!!!!! आप बहुत दयालु हैं। आपका बहुत बहुत धन्यवाद! –

+0

मेरे मामले में "CPP_DEFS = -D = HAVE_CONFIG_H" को "CPP_DEFS = -D = HAVE_NETINET_IN_H" में बदलें। – christophe

+0

लाइन के अंत में '-lthrift' क्यों है? यह काम करता हैं। – bits

0

कुछ खोज के बाद मैं कारण हो सकता है ... यह क्योंकि आपके जी ++ के संस्करण ... संक्षेप में , काम जीसीसी हैं:

जी ++ 4.4.6: ठीक है जी ++ 4.5.3: ठीक है जी ++ 4.6.1:

लिंक को अपरिभाषित संदर्भ के बारे में शिकायत: +०१२३५१६४१०६http://mail-archives.apache.org/mod_mbox/thrift-user/201107.mbox/%[email protected]%3E

http://mail-archives.apache.org/mod_mbox/thrift-dev/201107.mbox/%[email protected]%3E

+0

हाँ, आप सही हैं, g ++ 4.6.1 को -O1 या -O2 तर्क जोड़ना है, मैं josendf के मेकफ़ाइल का उपयोग करता हूं, सभी समस्या का समाधान करता हूं, वैसे भी धन्यवाद ^^ –

0

यहाँ ओएस एक्स के लिए एक उदाहरण है

पहले निर्भरता और बचत खुद को स्थापित, सबसे आसान brew से कोई लेना देना:

brew install boost 
brew install thrift 

ध्यान दें कि यदि आप है मैन्युअल रूप से बहाव को मैन्युअल रूप से स्थापित करने का प्रयास किया है, आपको पहले इसे अनइंस्टॉल करना पड़ सकता है।

Download thrift और ट्यूटोरियल संकलन:

cd ./thrift-0.8.0/tutorial 
thrift --gen cpp ./tutorial.thrift 
cd ./cpp 

निम्नलिखित (jedf समाधान के आधार पर) के साथ मौजूदा Makefile बदलें:

THRIFT_VER =thrift/0.8.0 
USR_DIR =/usr/local/Cellar 
THRIFT_DIR =${USR_DIR}/${THRIFT_VER} 
INCS_DIRS =-I${USR_DIR}/include -I${THRIFT_DIR}/include/thrift -I${USR_DIR}/boost/1.49.0/include/boost 
LIBS_DIRS =-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 

भागो सर्वर और ग्राहक:

./CppServer 
./CppClient 

इसके अलावा, जब भी आप उस बचत निम्न का उपयोग की आवश्यकता है तीसरे पक्ष के कोड संकलन करने की जरूरत:

export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/Cellar/thrift/0.8.0/lib/pkgconfig/