I’m trying to build a thrift server in c++ but i seem to be having a problem with the linking stage. Can anyone shed any light?
Here’s what i’m running. (forgive me being a c++ n00b):
g++ -Wall -L/usr/local/lib user_constants.o user_types.o UserService_server.o -lthrift
And here’s the output
user_types.o: In function `UserCollection::read(apache::thrift::protocol::TProtocol*)':
user_types.cpp:(.text+0xaba): undefined reference to `CollectionInformation::read(apache::thrift::protocol::TProtocol*)'
user_types.o: In function `UserCollection::write(apache::thrift::protocol::TProtocol*) const':
user_types.cpp:(.text+0xca7): undefined reference to `CollectionInformation::write(apache::thrift::protocol::TProtocol*) const'
UserService_server.o: In function `UserServiceProcessor::UserServiceProcessor(boost::shared_ptr<UserServiceIf>)':
UserService_server.cpp:(.text._ZN20UserServiceProcessorC2EN5boost10shared_ptrI13UserServiceIfEE[_ZN20UserServiceProcessorC5EN5boost10shared_ptrI13UserServiceIfEE]+0x33): undefined reference to `vtable for UserServiceProcessor'
UserService_server.cpp:(.text._ZN20UserServiceProcessorC2EN5boost10shared_ptrI13UserServiceIfEE[_ZN20UserServiceProcessorC5EN5boost10shared_ptrI13UserServiceIfEE]+0xaf): undefined reference to `UserServiceProcessor::process_getById(int, apache::thrift::protocol::TProtocol*, apache::thrift::protocol::TProtocol*, void*)'
UserService_server.cpp:(.text._ZN20UserServiceProcessorC2EN5boost10shared_ptrI13UserServiceIfEE[_ZN20UserServiceProcessorC5EN5boost10shared_ptrI13UserServiceIfEE]+0x136): undefined reference to `UserServiceProcessor::process_save(int, apache::thrift::protocol::TProtocol*, apache::thrift::protocol::TProtocol*, void*)'
UserService_server.cpp:(.text._ZN20UserServiceProcessorC2EN5boost10shared_ptrI13UserServiceIfEE[_ZN20UserServiceProcessorC5EN5boost10shared_ptrI13UserServiceIfEE]+0x1bd): undefined reference to `UserServiceProcessor::process_destroy(int, apache::thrift::protocol::TProtocol*, apache::thrift::protocol::TProtocol*, void*)'
UserService_server.cpp:(.text._ZN20UserServiceProcessorC2EN5boost10shared_ptrI13UserServiceIfEE[_ZN20UserServiceProcessorC5EN5boost10shared_ptrI13UserServiceIfEE]+0x23e): undefined reference to `UserServiceProcessor::process_search(int, apache::thrift::protocol::TProtocol*, apache::thrift::protocol::TProtocol*, void*)'
UserService_server.cpp:(.text._ZN20UserServiceProcessorC2EN5boost10shared_ptrI13UserServiceIfEE[_ZN20UserServiceProcessorC5EN5boost10shared_ptrI13UserServiceIfEE]+0x2bc): undefined reference to `UserServiceProcessor::process_searchByName(int, apache::thrift::protocol::TProtocol*, apache::thrift::protocol::TProtocol*, void*)'
UserService_server.cpp:(.text._ZN20UserServiceProcessorC2EN5boost10shared_ptrI13UserServiceIfEE[_ZN20UserServiceProcessorC5EN5boost10shared_ptrI13UserServiceIfEE]+0x33a): undefined reference to `UserServiceProcessor::process_searchByEmailAddress(int, apache::thrift::protocol::TProtocol*, apache::thrift::protocol::TProtocol*, void*)'
UserService_server.cpp:(.text._ZN20UserServiceProcessorC2EN5boost10shared_ptrI13UserServiceIfEE[_ZN20UserServiceProcessorC5EN5boost10shared_ptrI13UserServiceIfEE]+0x3b8): undefined reference to `UserServiceProcessor::process_checkUsernameExists(int, apache::thrift::protocol::TProtocol*, apache::thrift::protocol::TProtocol*, void*)'
UserService_server.cpp:(.text._ZN20UserServiceProcessorC2EN5boost10shared_ptrI13UserServiceIfEE[_ZN20UserServiceProcessorC5EN5boost10shared_ptrI13UserServiceIfEE]+0x436): undefined reference to `UserServiceProcessor::process_registerUser(int, apache::thrift::protocol::TProtocol*, apache::thrift::protocol::TProtocol*, void*)'
UserService_server.cpp:(.text._ZN20UserServiceProcessorC2EN5boost10shared_ptrI13UserServiceIfEE[_ZN20UserServiceProcessorC5EN5boost10shared_ptrI13UserServiceIfEE]+0x4b4): undefined reference to `UserServiceProcessor::process_verifyUser(int, apache::thrift::protocol::TProtocol*, apache::thrift::protocol::TProtocol*, void*)'
UserService_server.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)':
UserService_server.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)]+0x27): undefined reference to `apache::thrift::protocol::TBinaryProtocolT<apache::thrift::transport::TTransport>::VERSION_1'
UserService_server.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&)':
UserService_server.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&)]+0x48): undefined reference to `apache::thrift::protocol::TBinaryProtocolT<apache::thrift::transport::TTransport>::VERSION_MASK'
UserService_server.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&)]+0x53): undefined reference to `apache::thrift::protocol::TBinaryProtocolT<apache::thrift::transport::TTransport>::VERSION_1'
collect2: ld returned 1 exit status
Your build line looks a bit ‘thin.’ Are you sure that you’re picking up all the locations of the libraries using
-Land the libraries themselves using-l?Looking at the above, I’d say Boost and Apache are the culprits. Do you have to link them in seperately? Also, remeber than on some architectures, it’s expected that the library path variable (usually
LD_LIBRARY_PATH) needs to be set to the paths on your build command line at link time as well as runtime.