ubuntu linux 下eclipse c++编译boost thread程序出错解决方法

boost库编译设置参考这篇文章

http://blog.csdn.net/stanfordzhang/article/details/6330272

new个c++ project 输入下面测试程序

#include <boost/thread.hpp>
#include <iostream>

void hello()
{
  std::cout <<
    "Hello world, I'm a thread!"
    << std::endl;
}

int main(int argc, char* argv[])
{

boost::thread thrd(&hello);

thrd.join();


return 0;
}

 

出现下面错误


**** Build of configuration Debug for project test ****

make all
Building target: test
Invoking: GCC C++ Linker
g++  -o"test"  ./tt.o   
./tt.o: In function `main':
/host/linuxdoc/cpp/test/Debug/../tt.cpp:23: undefined reference to `boost::thread::join()'
/host/linuxdoc/cpp/test/Debug/../tt.cpp:26: undefined reference to `boost::thread::~thread()'
/host/linuxdoc/cpp/test/Debug/../tt.cpp:26: undefined reference to `boost::thread::~thread()'
./tt.o: In function `thread_data_base':
/usr/local/include/boost/thread/pthread/thread_data.hpp:65: undefined reference to `vtable for boost::detail::thread_data_base'
./tt.o: In function `thread<void (*)()>':
/usr/local/include/boost/thread/detail/thread.hpp:191: undefined reference to `boost::thread::start_thread()'
./tt.o: In function `~thread_data':
/usr/local/include/boost/thread/detail/thread.hpp:40: undefined reference to `boost::detail::thread_data_base::~thread_data_base()'
/usr/local/include/boost/thread/detail/thread.hpp:40: undefined reference to `boost::detail::thread_data_base::~thread_data_base()'
./tt.o:(.rodata._ZTIN5boost6detail11thread_dataIPFvvEEE[typeinfo for boost::detail::thread_data<void (*)()>]+0x8): undefined reference to `typeinfo for boost::detail::thread_data_base'
collect2: ld returned 1 exit status
make: *** [test] 错误 1

 

只要在项目右键的properties引入thread库就可以了,因为thread库是编译后才有的,需要引入。

添加”boost_thread“到c++ linker的libraries

 

 

其他需要编译的库估计也需要如此,备记。

转载于:https://www.cnblogs.com/wusee/archive/2012/03/18/2404435.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值