boostのVS 2005での使用


1.  http://www.boostpro.com/download/          boost  ,    ,     2005 static  

2.インストールが完了したら、C:Program Filesboostboost_1_51ヘッダファイルシステムディレクトリ(tools->options->VC++Directories->include files)を追加し、C:Program Filesboostboost_1_51libライブラリファイルシステムディレクトリに追加します.以下の図です.



boost在VS2005下的使用_第1张图片
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,class std::allocator>::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,class std::allocator>::~basic_string,class std::allocator>(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,class std::allocator> & __thiscall std::basic_string,class std::allocator>::operator+=(class std::basic_string,class std::allocator> 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,class std::allocator> & __thiscall std::basic_string,class std::allocator>::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,class std::allocator> & __thiscall std::basic_string,class std::allocator>::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,class std::allocator>::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,class std::allocator>::basic_string,class std::allocator>(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,class std::allocator>::basic_string,class std::allocator>(class std::basic_string,class std::allocator> 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::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::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::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)に変更し、コンパイルすれば通過します.
次の図を示します.
boost在VS2005下的使用_第2张图片