我正在运行 Apache 的 Thrift 教程:http://wiki.apache.org/thrift/ThriftUsageC%2B%2B我的 Thrift 版本是 0.9.1,我使用的是 OS X。我在本教程中搜索了类似的问题,虽然其他人也遇到了问题,但他们似乎与我遇到的问题并不相似。我有。
服务器可以正确编译和链接,客户端也可以正确编译。问题是在教程的最后一步链接客户端,我得到这个:
Undefined symbols for architecture x86_64:
"apache::thrift::transport::TSocket::TSocket(std::string, int)", referenced from:
_main in Something_client-e25162.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我通过该教程中的示例 Makefile 以及整个教程中的命令行构建过程收到了同样的错误。我的客户端代码是
我在 OS X 上运行,所以我添加了-stdlib=libstdc++
到命令行过程中的每一行。下面是我用来编译/链接的 Bash 示例(我的初始 Thrift 文件是 example.thrift):
#!/bin/bash
# Server
# Writing out each .cpp to compile, as opposed to the tutorial which uses *.cpp,
# since my client code is in the same directory.
g++ -stdlib=libstdc++ -DHAVE_INTTYPES_H -DHAVE_NETINET_IN_H -Wall -I/usr/local/include/thrift Something.cpp Something_server.cpp sample_constants.cpp sample_types.cpp -L/usr/local/lib -lthrift -o something
g++ -stdlib=libstdc++ -Wall -I/usr/local/include/thrift -c Something.cpp -o something.o
g++ -stdlib=libstdc++ -Wall -I/usr/local/include/thrift -c Something_server.cpp -o server.o
g++ -stdlib=libstdc++ -Wall -I/usr/local/include/thrift -c sample_constants.cpp -o constants.o
g++ -stdlib=libstdc++ -Wall -I/usr/local/include/thrift -c sample_types.cpp -o types.o
g++ -stdlib=libstdc++ -L/usr/local/lib *.o -o Something_server -lthrift
# Client
g++ -stdlib=libstdc++ -Wall -I/usr/local/include/thrift -c Something_client.cpp -o client.o
# THIS LINE PRODUCES THE UNDEFINED SYMBOLS ERROR - all of the above are successful
g++ -stdlib=libstdc++ -L/usr/local/lib client.o something.o constants.o types.o -o Something_client -lthrift
任何帮助,将不胜感激。我不明白为什么它找不到TSocket
实施即使libthrift
包含在链接器调用中。