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

 

 

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

posted @ 2012-03-18 11:26  无色  阅读(2285)  评论(0编辑  收藏  举报