I am running through Apache's Thrift tutorial: http://wiki.apache.org/thrift/ThriftUsageC%2B%2B My Thrift is version 0.9.1, and I'm on OS X. I've performed a search for similar problems with this tutorial, and while other people have also had issues they don't appear to be similar to the one I'm having.
The server both compiles and links properly, and the client compiles correctly as well. The problem is linking the client at the very last step of the tutorial, where I get this:
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)
I have received this same error through the sample Makefile in that tutorial as well as following the command line build procedure throughout the tutorial. My client code is a
I am running on OS X, so I have added -stdlib=libstdc++
to each line in the command line procedure. Here's a Bash example of exactly what I'm using to compile/link (my initial Thrift file was sample.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
Any help would be appreciated. I can't figure out why it can't find the TSocket
implementation even though libthrift
is included in the linker invocation.