boost在VS2005下的使用

1. 从http://www.boostpro.com/download/下载最新的预编译好的boost版本,然后运行,安装是选择2005的static版本

2. 安装完成后,把C:\Program Files\boost\boost_1_51添加到头文件系统目录(tools->options->VC++ Directories->include files),把C:\Program Files\boost\boost_1_51\lib添加到库文件系统目录,如下图:


3. 新建一个console工程,输入如下代码:

#include <iostream>  
#include <boost/thread.hpp>   
#include <boost/date_time.hpp>       

void workerFunc()  
{  
	boost::posix_time::seconds workTime(3);          
	std::cout << "Worker: running" << std::endl;    

	// Pretend to do something useful... 
	boost::this_thread::sleep(workTime);          
	std::cout << "Worker: finished" << std::endl;  
}    

int _tmain(int argc, _TCHAR* argv[])
{  
	std::cout << "main: startup" << std::endl;          
	boost::thread workerThread(workerFunc);    

	std::cout << "main: waiting for thread" << std::endl;          
	workerThread.join();    

	std::cout << "main: done" << std::endl;          
	return 0;  
}

4. 编译

如果出现如下错误:

1>------ Build started: Project: boost_tester, Configuration: Debug Win32 ------
1>Compiling...
1>stdafx.cpp
1>Compiling...
1>boost_tester.cpp
1>Linking...
1>msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: char const * __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::c_str(void)const " (?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEPBDXZ) already defined in libboost_thread-vc80-mt-sgd-1_51.lib(thread.obj)
1>msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)" (??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in libboost_thread-vc80-mt-sgd-1_51.lib(thread.obj)
1>msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > & __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::operator+=(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??Y?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV01@ABV01@@Z) already defined in libboost_thread-vc80-mt-sgd-1_51.lib(thread.obj)
1>msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > & __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::operator+=(char const *)" (??Y?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV01@PBD@Z) already defined in libboost_thread-vc80-mt-sgd-1_51.lib(thread.obj)
1>msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > & __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::operator=(char const *)" (??4?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV01@PBD@Z) already defined in libboost_thread-vc80-mt-sgd-1_51.lib(thread.obj)
1>msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: bool __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::empty(void)const " (?empty@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBE_NXZ) already defined in libboost_thread-vc80-mt-sgd-1_51.lib(thread.obj)
1>msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(char const *)" (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z) already defined in libboost_thread-vc80-mt-sgd-1_51.lib(thread.obj)
1>msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z) already defined in libboost_thread-vc80-mt-sgd-1_51.lib(thread.obj)
1>msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: static unsigned int __cdecl std::char_traits<char>::length(char const *)" (?length@?$char_traits@D@std@@SAIPBD@Z) already defined in libboost_thread-vc80-mt-sgd-1_51.lib(thread.obj)
1>msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: static unsigned int __cdecl std::numeric_limits<unsigned int>::max(void)" (?max@?$numeric_limits@I@std@@SAIXZ) already defined in libboost_thread-vc80-mt-sgd-1_51.lib(thread.obj)
1>msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: static unsigned int __cdecl std::numeric_limits<unsigned int>::min(void)" (?min@?$numeric_limits@I@std@@SAIXZ) already defined in libboost_thread-vc80-mt-sgd-1_51.lib(thread.obj)
1>msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: static __int64 __cdecl std::numeric_limits<__int64>::max(void)" (?max@?$numeric_limits@_J@std@@SA_JXZ) already defined in libboost_thread-vc80-mt-sgd-1_51.lib(thread.obj)
1>msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: static __int64 __cdecl std::numeric_limits<__int64>::min(void)" (?min@?$numeric_limits@_J@std@@SA_JXZ) already defined in libboost_thread-vc80-mt-sgd-1_51.lib(thread.obj)
1>LINK : fatal error LNK1104: cannot open file 'libboost_thread-vc80-mt-gd-1_51.lib'


则做如下改动(project->properties->c/c++ ->code generation, 将Multi-threaded Debug DLL (/MDd)改为Multi-threaded Debug (/MTd),编译即可通过。

如下图:


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值