QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2204|回复: 5

使用boost的thread库时遇到一个奇怪的问题

[复制链接]
发表于 2005-7-2 14:06:53 | 显示全部楼层 |阅读模式
这是我第一次使用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在安装后都没有进行什么改动,相关设置都是默认的。
发表于 2005-7-2 15:15:30 | 显示全部楼层
请贴出具体的编译命令。
回复

使用道具 举报

 楼主| 发表于 2005-7-2 16:24:44 | 显示全部楼层
就这个啊
g++ -o thread thread.cpp
回复

使用道具 举报

 楼主| 发表于 2005-7-3 15:27:53 | 显示全部楼层
有没有人知道阿,急用
      
回复

使用道具 举报

发表于 2005-7-4 13:08:25 | 显示全部楼层
你的boost没有装好
回复

使用道具 举报

 楼主| 发表于 2005-7-4 14:57:25 | 显示全部楼层
[quote:6ca9d6dfa5="snaileo"]你的boost没有装好[/quote]
不会吧,FC3和FC4安装时都自带了boost
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-11-5 17:32 , Processed in 0.042863 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表