Apache Thrift教程中的C ++链接器错误-未定义符号 [英] C++ linker error in Apache Thrift tutorial - undefined symbols

查看:151
本文介绍了Apache Thrift教程中的C ++链接器错误-未定义符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在遍历Apache的Thrift教程: http://wiki.apache.org /thrift/ThriftUsageC%2B%2B 我的Thrift版本是0.9.1,我在OS X上.我已经在本教程中搜索了类似的问题,而其他人也遇到了问题似乎与我所拥有的不相似.

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)

在该教程的示例Makefile中,以及在整个教程中遵循命令行构建过程的过程中,我都收到了相同的错误.我的客户代码是

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

我在OS X上运行,因此在命令行过程的每行中都添加了-stdlib=libstdc++.这是一个Bash示例,确切地说明了我正在使用什么进行编译/链接(我最初的Thrift文件是sample.thrift):

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

任何帮助将不胜感激.我不知道为什么即使链接器调用中包含了libthrift,也找不到TSocket实现.

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.

推荐答案

我在OSX Mavericks上遇到了类似的情况(我相信),这已经有一段时间了.由于您也使用clang,我也可能会在OSX上使用它?

I ran into something similar on OSX Mavericks (I believe), this was a while back. Since you're using clang as well I take it you might be on OSX too?

无论如何,我最终要做的是按照C ++ 11标准进行编译,并将其用于stdlib libc++,而不是libstdc++.当前版本的clang可以很好地解决这两个问题.

Anyways, what I ended up doing was compiling on the C++11 standard and using for the stdlib libc++ as opposed to libstdc++. Current versions of clang deal well with both.

所以您的编译行可能最终看起来像这样:

So your compile lines would probably end up looking something like this:

g++ -std=c++11 -stdlib=libc++ -DHAVE_INTTYPES_H -DHAVE_NETINET_IN_H -Wall -I/usr/local/include/thrift Foo.cpp Foo_server.cpp foo_constants.cpp foo_types.cpp -L/usr/local/lib -lthrift -o foo

我还隐约记得我不得不在linux和gcc上求助于c ++ 0x,但是这些都受编译器/版本的限制.

I also vaguely recall I had to resort to c++0x on linux and gcc, but these are subject to compiler/version.

这篇关于Apache Thrift教程中的C ++链接器错误-未定义符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆