[英]Linking against boost_thread fails under Ubuntu 11.10
I already updated to the new Ubuntu 11.10.The problem is now, that the software I am working on is not linking any more. 我已经更新到新的Ubuntu 11.10。现在的问题是,我正在处理的软件不再链接了。 I found this wiki entry which seems to describe the problem.
我发现这个 wiki条目似乎描述了这个问题。 None the less I am unable to fix it.
尽管如此,我无法修复它。 To reproduce the problem I wrote the following small test program:
为了重现这个问题,我编写了以下小测试程序:
#include <iostream>
#include <boost/thread.hpp>
void blubb() {
std::cout << "hello world" << std::endl;
}
int main() {
boost::thread t(&blubb);
t.join();
}
Than I use the following command to compile: 比我使用以下命令编译:
g++ -o test -lboost_thread test.cc
The output I get is the following: 我得到的输出如下:
/tmp/cc0O0dAC.o: In function `main':
test.cc:(.text+0x49): undefined reference to `boost::thread::join()'
test.cc:(.text+0x55): undefined reference to `boost::thread::~thread()'
test.cc:(.text+0x70): undefined reference to `boost::thread::~thread()'
/tmp/cc0O0dAC.o: In function `boost::detail::thread_data_base::thread_data_base()':
test.cc:(.text._ZN5boost6detail16thread_data_baseC2Ev[_ZN5boost6detail16thread_data_baseC5Ev]+0x24): undefined reference to `vtable for boost::detail::thread_data_base'
/tmp/cc0O0dAC.o: In function `boost::thread::thread<void (*)()>(void (*)(), boost::disable_if<boost::is_convertible<void (*&)(), boost::detail::thread_move_t<void (* ()> >, boost::thread::dummy*>::type)':
test.cc:(.text._ZN5boost6threadC2IPFvvEEET_NS_10disable_ifINS_14is_convertibleIRS4_NS_6detail13thread_move_tIS4_EEEEPNS0_5dummyEE4typeE[_ZN5boost6threadC5IPFvvEEET_NS_10disable_ifINS_14is_convertibleIRS4_NS_6detail13thread_move_tIS4_EEEEPNS0_5dummyEE4typeE]+0x30): undefined reference to `boost::thread::start_thread()'
/tmp/cc0O0dAC.o: In function `boost::detail::thread_data<void (*)()>::~thread_data()':
test.cc:(.text._ZN5boost6detail11thread_dataIPFvvEED2Ev[_ZN5boost6detail11thread_dataIPFvvEED5Ev]+0x1f): undefined reference to `boost::detail::thread_data_base::~thread_data_base()'
/tmp/cc0O0dAC.o:(.rodata._ZTIN5boost6detail11thread_dataIPFvvEEE[typeinfo for boost::detail::thread_data<void (*)()>]+0x10): undefined reference to `typeinfo for boost::detail::thread_data_base'
collect2: ld returned 1 exit status
I also tried to add -lpthread and -pthread in several orders with no success. 我还尝试在几个订单中添加-lpthread和-pthread但没有成功。 This command works smoothly on an older Ubuntu version.
此命令在较旧的Ubuntu版本上运行顺利。 What am I doing wrong (I have similar problems with PCRE and Google Protocol Buffers).
我做错了什么(我在PCRE和Google Protocol Buffers方面遇到了类似的问题)。
Thanks in advance for any help! 在此先感谢您的帮助!
Ok I mamaged to fix it, it is ridiculous: 好吧我修好了它,这太荒谬了:
as written in the question 正如问题中所写
g++ -o test -lboost_thread test.cc
does not work, but 不起作用,但是
g++ -o test test.cc -lboost_thread
does... So not only the order of libraries matter, but also the source files must be written before the dependencies... ...所以不仅库的顺序很重要,而且必须在依赖项之前写入源文件......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.