1

我正在尝试用 C++ 构建一个节俭服务器,但我似乎在链接阶段遇到了问题。任何人都可以解释一下吗?

这就是我正在运行的。(请原谅我是 C++ n00b):

g++ -Wall -L/usr/local/lib  user_constants.o user_types.o UserService_server.o -lthrift

这是输出

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
4

2 回答 2

2

您的构建线看起来有点“细”。您确定您正在获取库 using-L和库本身 using的所有位置-l吗?

综上所述,我想说 Boost 和 Apache 是罪魁祸首。你必须单独链接它们吗?此外,请记住,与某些架构相比,库路径变量(通常LD_LIBRARY_PATH)需要在链接时和运行时设置为构建命令行上的路径。

于 2012-05-17T13:26:19.643 回答
0

Usual thrift generates three .cpp file for each interface (*.thrift) you should add all of them ( UserService.cpp and UserService_constants.cpp, UserService_types.cpp ) to g++ arguments.

于 2013-04-13T15:44:01.360 回答