读书人

boost thred库编译报错解决办法

发布时间: 2012-06-02 14:16:14 作者: rapoo

boost thred库编译报错
// 源码
#include <boost/thread/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;
}

// 编译
g++ thread1.cpp -o t1 -lboost_thread

// 错误
/tmp/ccGySHNO.o: In function `boost::detail::thread_data<void (*)()>::~thread_data()':
thread1.cpp:(.text._ZN5boost6detail11thread_dataIPFvvEED0Ev[boost::detail::thread_data<void (*)()>::~thread_data()]+0x17): undefined reference to `boost::detail::thread_data_base::~thread_data_base()'
/tmp/ccGySHNO.o: In function `boost::detail::thread_data<void (*)()>::~thread_data()':
thread1.cpp:(.text._ZN5boost6detail11thread_dataIPFvvEED1Ev[boost::detail::thread_data<void (*)()>::~thread_data()]+0x17): undefined reference to `boost::detail::thread_data_base::~thread_data_base()'
/tmp/ccGySHNO.o: In function `boost::detail::thread_data_base::thread_data_base()':
thread1.cpp:(.text._ZN5boost6detail16thread_data_baseC2Ev[boost::detail::thread_data_base::thread_data_base()]+0x16): undefined reference to `vtable for boost::detail::thread_data_base'
/tmp/ccGySHNO.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)':

[解决办法]
重新编译boost库吧
[解决办法]
我采用嵌入源文件编译的方式也遇到了同样的问题,求高人解答

读书人网 >C++

热点推荐