1.参考《实战准标准库Boost,配置Boost的VS2008开发环境》
2.参考《VS2010安装Boost》
一、下载Boost库
boost_1_50_0.zip (http://www.boost.org/users/download/),解压到F:boost_1_50_0
要做Python开发的还需下载: python-2.7.3.msi (http://www.python.org/)
二、编译Boost库
1. 编译jam
在工具栏启动Visual Studio 2008 Command Prompt(VS2008命令提示) , 进入 boost的解压目录,即F:\boost_1_50_0, 输入bootstrap,便在boost根目录下生成bjam.exe文件。具体命令如下:
>F:\
>cd F:\boost_1_50_0
>bootstrap
【 注:在网上看了许多教程,老版本需要进入tools/jam/目录下运行build_dist.bat 生成bjam.exe,这点与老版本不同。】
2. 编译boost
如果需要去掉编译过程中的一些warning,可以在tools\build\v2的user-config.jam文件中加入以下这一行:
using msvc : : : <compileflags>/wd4819 <compileflags>/D_CRT_SECURE_NO_DEPRECATE <compileflags>/D_SCL_SECURE_NO_DEPRECATE <compileflags>/D_SECURE_SCL=0 ;
然后双击bjam.exe;——时间有些长,请耐心等待
三、配置VS2008开发环境
在菜单栏的“工具”——“选项”——“项目和解决方案”——“VC++目录”,“平台”选择“Win32”。
“显示以下内容的目录”选择“库文件”,点击“新建”按钮,文件夹选择“F:\boost_1_50_0\stage\lib”
“显示以下内容的目录”选择“包含文件”,点击“新建”按钮,文件夹选择“F:\boost_1_50_0”
四、代码测试
- #include <stdlib.h>
- #include <boost/config.hpp>
- #include <iostream>
- #include <vector>
- #include <string>
- #include <boost/graph/adjacency_list.hpp>
- #include <boost/tuple/tuple.hpp>
- enum family
- { Jeanie, Debbie, Rick, John, Amanda, Margaret, Benjamin, N };
- int main()
- {
- using namespace boost;
- const char *name[] = { "Jeanie", "Debbie", "Rick", "John", "Amanda",
- "Margaret", "Benjamin"
- };
- adjacency_list <> g(N);
- add_edge(Jeanie, Debbie, g);
- add_edge(Jeanie, Rick, g);
- add_edge(Jeanie, John, g);
- add_edge(Debbie, Amanda, g);
- add_edge(Rick, Margaret, g);
- add_edge(John, Benjamin, g);
- graph_traits < adjacency_list <> >::vertex_iterator i, end;
- graph_traits < adjacency_list <> >::adjacency_iterator ai, a_end;
- property_map < adjacency_list <>, vertex_index_t >::type
- index_map = get(vertex_index, g);
- for (boost::tie(i, end) = vertices(g); i != end; ++i) {
- std::cout << name[get(index_map, *i)];
- boost::tie(ai, a_end) = adjacent_vertices(*i, g);
- if (ai == a_end)
- std::cout << " has no children";
- else
- std::cout << " is the parent of ";
- for (; ai != a_end; ++ai) {
- std::cout << name[get(index_map, *ai)];
- if (boost::next(ai) != a_end)
- std::cout << ", ";
- }
- std::cout << std::endl;
- }
- system("pause");
- return EXIT_SUCCESS;
- }