记: 在调试boost::thread库遇到的一个小问题

今天在使用boost::thread库时,
示例:

1
2
3
4
5
6
7
8
9
10
11
void test ( )
{
  std :: cout << "run!\n" ;
}

int main ( int argc , char * argv [ ] )
{
    boost :: thread thread1 ( &test ) ;
    thread1. join ( ) ;
    return 0 ;
}

一直编译不过,提示:

Z:/cpp/boost/t2.cpp:25: undefined reference to `_imp___ZN5boost6thread4joinEv'
Z:/cpp/boost/t2.cpp:27: undefined reference to `_imp___ZN5boost6threadD1Ev'
Z:/cpp/boost/t2.cpp:27: undefined reference to `_imp___ZN5boost6threadD1Ev'
obj\Debug\t2.o: In function `thread':
E:/boost/include/boost-1_46_1/boost/thread/detail/thread.hpp:27: undefined reference to `_imp___ZN5boost6thread12start_threadEv'
collect2: ld returned 1 exit status

开始怀疑版本boost 1.46.1编译不正确,重新编译了后问题依旧,最后查看thread/detail/config.hpp配置文件,

经测试我当前环境win32下,boost::thread库默认定义为BOOST_THREAD_USE_DLL的动态编译,这显然和我当前的静态编译方式不符,
分别参考两个参数的说明:

BOOST_THREAD_USE_LIB
For compilers supporting auto-tss cleanup
with Boost.Threads lib, use Boost.Threads lib

BOOST_THREAD_USE_DLL
For compilers not yet supporting auto-tss cleanup
with Boost.Threads lib, use Boost.Threads dll

隧在代码中预定义编译符号
...
#define BOOST_THREAD_USE_LIB
...
编译正常通过。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值