boost1.50的thread库无法解析外部符号void __cdecl boost::tss_cleanup_implemented(void) boost、date_time和thread库都编

boost1.50的thread库无法解析外部符号void __cdecl boost::tss_cleanup_implemented(void)
boost、date_time和thread库都编译了但使用thread库时没有办法编译!
提示:
1>BootThread.obj : error LNK2019: 无法解析的外部符号 "void __cdecl boost::tss_cleanup_implemented(void)" (?tss_cleanup_implemented@boost@@YAXXZ),该符号在函数 "void __cdecl boost::`anonymous namespace'::create_current_thread_tls_key(void)" (?create_current_thread_tls_key@?A0x60de1d11@boost@@YAXXZ) 中被引用

1>C:\Users\ZZD\documents\visual studio 2010\Projects\BootThread\Debug\BootThread.exe : fatal error LNK1120: 1 个无法解析的外部命令


解决方案:

#define BOOST_HAS_WINTHREADS
#define BOOST_THREAD_BUILD_DLL

定义这两个宏

#define BOOST_DATA_TIME_SOURCE
#define BOOST_THREAD_NO_LIB
#define BOOST_HAS_WINTHREADS
#define BOOST_THREAD_BUILD_DLL

#include <string>
#include <iostream>
#include "boost/thread.hpp"
//#ifdef _MSC_VER
//extern "C" void tss_cleanup_implemented(void){}
#include "libs/thread/src/win32/thread.cpp"
#include "libs/thread/src/win32/tss_dll.cpp"
#include "libs/thread/src/win32/tss_pe.cpp"
//#endif
using namespace boost;
using namespace std;


boost::mutex io_mu;


void printing(int& x, const string& str)
{
for(int Index = 0; Index < 5; ++Index)
{
mutex::scoped_lock lock(io_mu);
cout<< str << ++x<< endl;
this_thread::sleep(posix_time::millisec(100));
}
}




int _tmain(int argc, _TCHAR* argv[])
{
int x; //原子操作的计数器


//使用临时thread对象启动线程
thread(printing,boost::ref(x),"hello"); //向函数传递多个参数
thread(printing,boost::ref(x),"boost"); //使用ref库传递引用


this_thread::sleep(posix_time::seconds(2));  //等待2秒钟


return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值