原文地址:http://blog.csdn.net/ztz0223/article/details/7764850
1、在c盘创建一个文件夹boost_1_50_0
2、下载最新的boost 库1.50到d盘,文件夹为boost_1_50_0
3、整个文件夹如下:
- D:\>cd boost_1_50_0
- D:\boost_1_50_0>dir
- Volume in drive D is D
- Volume Serial Number is 7CF4-5846
- Directory of D:\boost_1_50_0
- 2012/07/19 21:13 <DIR> .
- 2012/07/19 21:13 <DIR> ..
- 2012/07/19 21:10 <DIR> boost
- 2012/05/27 03:33 866 boost-build.jam
- 2012/05/27 03:33 1,054 boost.css
- 2012/05/27 03:33 6,308 boost.png
- 2012/06/26 22:07 18,606 boostcpp.jam
- 2012/05/27 03:33 2,545 bootstrap.bat
- 2012/05/27 03:33 10,324 bootstrap.sh
- 2012/07/19 21:10 <DIR> doc
- 2012/05/27 03:33 794 index.htm
- 2012/05/27 03:33 5,848 index.html
- 2012/05/27 03:33 298 INSTALL
- 2012/05/27 03:33 10,423 Jamroot
- 2012/07/19 21:13 <DIR> libs
- 2012/05/27 03:33 1,361 LICENSE_1_0.txt
- 2012/07/19 21:13 <DIR> more
- 2012/05/27 03:33 2,757 rst.css
- 2012/07/19 21:13 <DIR> status
- 2012/07/19 21:13 <DIR> tools
- 12 File(s) 61,184 bytes
- 8 Dir(s) 52,751,728,640 bytes free
- D:\boost_1_50_0>
4、开启vc2008的自带的cmd工具,开始如下操作:
- D:\boost_1_50_0>cd tools\build\v2
- D:\boost_1_50_0\tools\build\v2>bootstrap.bat
- Bootstrapping the build engine
- Bootstrapping is done. To build, run:
- .\b2 --prefix=DIR install
- D:\boost_1_50_0\tools\build\v2>
5、不要按照它的操作提示来,我们回到根目录,执行b2.exe操作,这个操作需要到根目录下面做,自然就要使用相对路径call b2.exe,同时指定编译工具为msvc 9.0,以后安装的路径,c:\boost_1_50_0:
- D:\boost_1_50_0\tools\build\v2>cd ../../..
- D:\boost_1_50_0>tools\build\v2\b2.exe toolset=msvc-9.0 --build-type=complete --prefix="c:\boost_1_50_0" stage
- Performing configuration checks
6、执行安装过程:
- D:\boost_1_50_0>tools\build\v2\b2.exe toolset=msvc-9.0 --build-type=complete --prefix="c:\boost_1_50_0" install
一切ok。
下一步就是测试是否ok了。
添加vc项目头文件和lib路径:
测试一个网络上下载的的代码:
- #include <iostream>
- #include <boost/asio.hpp>
- #include <boost/date_time/posix_time/posix_time.hpp>
- boost::asio::io_service io;
- boost::asio::deadline_timer t(io, boost::posix_time::seconds(5));
- boost::asio::deadline_timer t1(io, boost::posix_time::seconds(3));
- void print(const boost::system::error_code& e)
- //要求回调函数必须具有该参数
- {
- if (e)
- {
- std::cout << "Hello, error!/n";
- }
- std::cout << "Hello, world!/n";
- }
- void cancel(const boost::system::error_code&)
- {
- t.cancel();
- }
- int main()
- {
- t.async_wait(print);
- t1.async_wait(cancel);
- io.run();
- return 0;
- }