#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