我正在使用Ubuntu + Eclipse并安装了boost(不确定是否正确)。我使用apt-get install libboost *
安装了Boost我测试了一些简单的代码,似乎提升工作正常。
但是,当我尝试学习线程部分时,下面的代码不起作用。
#include <boost/thread/thread.hpp>
#include <iostream>
using namespace std;
void hello()
{
cout<<"hello!"<<endl;
}
int main()
{
boost::thread thrd(&hello);
cout<<"Just a test!"<<endl;
}
错误信息如下,有4个错误。
Severity and Description Path Resource Location Creation Time Id
/usr/local/include/boost/thread/detail/thread.hpp undefined reference to `boost::detail::thread_data_base::~thread_data_base()' FirstCppProject line 40 1260656497961 200
Severity and Description Path Resource Location Creation Time Id
/usr/local/include/boost/thread/detail/thread.hpp undefined reference to `boost::thread::start_thread()' FirstCppProject line 191 1260656497967 202
Severity and Description Path Resource Location Creation Time Id
/usr/local/include/boost/thread/pthread/thread_data.hpp undefined reference to `vtable for boost::detail::thread_data_base' FirstCppProject line 65 1260656497965 201
Severity and Description Path Resource Location Creation Time Id
undefined reference to `boost::thread::~thread()' FirstCppProject test.cpp line 15 1260656497959 199
如果我的问题太天真,请原谅我。请提供您认为可能帮助我的任何信息。
答案 0 :(得分:4)
你必须链接到线程库libboost_thread _...
答案 1 :(得分:1)
有时你需要告诉你链接库的位置,它会找出链接的链接。
答案 2 :(得分:1)
添加链接器 - &gt; 1.右键点击该项目 2.在属性窗口中选择 3.点击c / c ++构建 4.选择设置 5.并选择库 6.然后你可以添加连接器:boost_thread和boost_system等