|
这是我第一次使用boost的thread库,出错代码如下
[code:1]
//thread.cpp
#include <boost/thread.hpp>
#include <iostream>
boost::mutex io_mutex;
struct count
{
static int num;
int id;
count(): id(num++) {}
int do_count(int n)
{
for(int i=0; i<n; ++i)
{
boost::mutex::scoped_lock lock(io_mutex);
std::cout << id << ": " << i << std::endl;
}
return id;
}
};
int count::num = 1;
int main(int argc, char* argv[])
{
count c1;
boost::thread thrd1(boost::bind(&count::do_count, &c1, 10));
thrd1.join();
return 0;
}
[/code:1]
在FC4下用g++ -o thread thread.cpp进行编译时,报如下错误
/tmp/ccrdwdRy.o(.text+0xdc): In function `main':
thread.cpp: undefined reference to
`boost::thread::thread(boost::function0<void,
std::allocator<boost::function_base> > const&)'
/tmp/ccrdwdRy.o(.text+0x11f):thread.cpp: undefined reference to
`boost::thread::join()'
/tmp/ccrdwdRy.o(.text+0x133):thread.cpp: undefined reference to
`boost::thread::~thread()'
/tmp/ccrdwdRy.o(.text+0x14d):thread.cpp: undefined reference to
`boost::thread::~thread()'
/tmp/ccrdwdRy.o(.text+0x195): In function `__tcf_1':
thread.cpp: undefined reference to `boost::mutex::~mutex()'
/tmp/ccrdwdRy.o(.text+0x1f: In function
`__static_initialization_and_destruction_0(int, int)':
thread.cpp: undefined reference to `boost::mutex::mutex()'
/tmp/ccrdwdRy.o(.gnu.linkonce.t._ZN5boost6detail6thread8lock_opsINS_5mutexEE4lockERS3_[boost::detail::thread::lock_ops<boost::mutex>::lock(boost::mutex&)]+0xd):
In function
`boost::detail::thread::lock_ops<boost::mutex>::lock(boost::mutex&)':
thread.cpp: undefined reference to `boost::mutex::do_lock()'
/tmp/ccrdwdRy.o(.gnu.linkonce.t._ZN5boost6detail6thread11scoped_lockINS_5mutexEE4lockEv[boost::detail::thread::scoped_lock<boost::mutex>::lock()]+0x29):
In function `boost::detail::thread::scoped_lock<boost::mutex>::lock()':
thread.cpp: undefined reference to `boost::lock_error::lock_error()'
/tmp/ccrdwdRy.o(.gnu.linkonce.t._ZN5boost6detail6thread11scoped_lockINS_5mutexEE4lockEv[boost::detail::thread::scoped_lock<boost::mutex>::lock()]+0x5:thread.cpp:
undefined reference to `boost::lock_error::~lock_error()'
/tmp/ccrdwdRy.o(.gnu.linkonce.t._ZN5boost6detail6thread11scoped_lockINS_5mutexEE4lockEv[boost::detail::thread::scoped_lock<boost::mutex>::lock()]+0x5d):thread.cpp:
undefined reference to `typeinfo for boost::lock_error'
/tmp/ccrdwdRy.o(.gnu.linkonce.t._ZN5boost6detail6thread8lock_opsINS_5mutexEE6unlockERS3_[boost::detail::thread::lock_ops<boost::mutex>::unlock(boost::mutex&)]+0xd):
In function
`boost::detail::thread::lock_ops<boost::mutex>::unlock(boost::mutex&)':
thread.cpp: undefined reference to `boost::mutex::do_unlock()'
/tmp/ccrdwdRy.o(.gnu.linkonce.t._ZN5boost6detail6thread11scoped_lockINS_5mutexEE6unlockEv[boost::detail::thread::scoped_lock<boost::mutex>::unlock()]+0x2c):
In function `boost::detail::thread::scoped_lock<boost::mutex>::unlock()':
thread.cpp: undefined reference to `boost::lock_error::lock_error()'
/tmp/ccrdwdRy.o(.gnu.linkonce.t._ZN5boost6detail6thread11scoped_lockINS_5mutexEE6unlockEv[boost::detail::thread::scoped_lock<boost::mutex>::unlock()]+0x5b):thread.cpp:
undefined reference to `boost::lock_error::~lock_error()'
/tmp/ccrdwdRy.o(.gnu.linkonce.t._ZN5boost6detail6thread11scoped_lockINS_5mutexEE6unlockEv[boost::detail::thread::scoped_lock<boost::mutex>::unlock()]+0x60):thread.cpp:
undefined reference to `typeinfo for boost::lock_error'
collect2: ld 返回 1
也在FC3下试过,有同样的报错。我的FC3和FC4在安装后都没有进行什么改动,相关设置都是默认的。 |
|