#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;
}
我跑试图编译这个程序,并得到了这些错误:升压线程错误:未定义参考
/usr/include/boost/thread/pthread/mutex.hpp:40: undefined reference to
`boost::thread_resource_error::thread_resource_error()'
/usr/include/boost/thread/pthread/mutex.hpp:40: undefined reference to
`boost::thread_resource_error::~thread_resource_error()'
/usr/include/boost/thread/pthread/mutex.hpp:40: undefined reference to
`typeinfo for boost::thread_resource_error'
./src/thread.o: In function `condition_variable':
/usr/include/boost/thread/pthread/condition_variable_fwd.hpp:33:
undefined reference to `boost::thread_resource_error::thread_resource_error()'
/usr/include/boost/thread/pthread/condition_variable_fwd.hpp:33:
undefined reference to `boost::thread_resource_error::~thread_resource_error()'
/usr/include/boost/thread/pthread/condition_variable_fwd.hpp:33: \
undefined reference to `typeinfo for boost::thread_resource_error'
./src/thread.o: In function `thread_data_base':
/usr/include/boost/thread/pthread/thread_data.hpp:54:
undefined reference to `vtable for boost::detail::thread_data_base'
./src/thread.o: In function `thread<void (*)()>':
/usr/include/boost/thread/detail/thread.hpp:188:
undefined reference to `boost::thread::start_thread()'
./src/thread.o: In function `~thread_data':
/usr/include/boost/thread/detail/thread.hpp:40:
undefined reference to `boost::detail::thread_data_base::~thread_data_base()'
/usr/include/boost/thread/detail/thread.hpp:40: undefined reference to
`boost::detail::thread_data_base::~thread_data_base()'
任何一个可以告诉我为什么我收到这个错误?
听起来升压未正确安装在系统上 – riwalk 2010-08-27 13:04:45
但我的 '的#include <升压/算法/ string.hpp> 的#include 的#include <升压/ thread.hpp> 使用命名空间std; 使用命名空间提升; int main() { \t string str1; \t cin >> str1; \t // string str1(“hello world!”); \t to_upper(str1); \t cout << str1; return 0; } '完美运行 –
lal
2010-08-27 13:08:58
我发现它需要在ubuntu上安装libboost-thread包 – lal 2010-08-27 13:22:08