我正在尝试构建简单的boost :: thread示例以进行测试。 其他使用g ++编译的简单代码。
我检查了其他stackoverflow答案,但这对我没有帮助。
有人可以帮我吗?
这是我的代码:
#include <iostream>
#include <boost/thread.hpp>
using namespace std;
class CThreadIO
{
public:
void TestThreadFirst()
{
while (true)
{
cout << "1 ";
boost::this_thread::sleep(boost::posix_time::millisec(500));
}
}
void TestThreadSecond(int num)
{
while (true)
{
cout << num << " ";
boost::this_thread::sleep(boost::posix_time::millisec(500));
}
}
};
int main()
{
CThreadIO io;
boost::thread th1 = boost::thread(boost::bind(&CThreadIO::TestThreadFirst, &io));
boost::thread th2 = boost::thread(boost::bind(&CThreadIO::TestThreadSecond, &io, 2));
th1.join();
th2.join();
return 0;
}
错误消息:
$ g++ thread.cpp
Undefined symbols for architecture x86_64:
"boost::this_thread::interruption_point()", referenced from:
boost::condition_variable::wait(boost::unique_lock<boost::mutex>&) in thread-d302d6.o
....
....
boost::_bi::list2<boost::_bi::value<CThreadIO*>, boost::_bi::value<int> > > > in thread-d302d6.o
"vtable for boost::detail::thread_data_base", referenced from:
boost::detail::thread_data_base::thread_data_base() in thread-d302d6.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)