配置过程主要参考 博客园finallyly的 vs2008boost安装手记 。 VS2008也可参考此过程。
一.下载资源
boost_1_50_0.zip (http://www.boost.org/users/download/)
icu4c-3_8_1-src.zip (http://www.icu-project.org/download/3.8.html)
python-2.7.3.msi (http://www.python.org/)
zlib-1.2.7.zip (http://www.zlib.net/)
bzip2-1.0.6.tar.gz ( http://www.bzip.org/downloads.html )
二. 准备工作
编译boost库之前,需要做一些准备工作。下载一些Open Source的包,来支持boost特定库的需要。
1. ICU
ICU提供了unicode和国际化支持,目前的版本是3.8.1。ICU的主页是http://www.icu-project.org/。
(1). 下载
可以从http://www.icu-project.org/download/3.8.html下载源代码版本和使用VS2005编译的版本。推荐下载源代码版本自己进行编译,以避免依赖于VS2005的运行时库。
(2). 编译
ICU的编译比较简单,打开ICU源代码目录下的source\allinone\allinone.sln,需要转换到VS2008格式,直接转换即可。然后,选择release,Rebuild Solution即可。
(3). 测试
将编译出来的bin目录加入到系统的PATH目录中去。然后,重新打开allinone.sln工程。
需要通过测试的项目
cintltst项目 intltest项目 iotest
分别设置成启动项目,运行即可。
2. bzip
将bzip2-1.0.6.tar.gz解压到G:\boost_lib文件夹下。
bzip的主页是 http://www.bzip.org/,从http://www.bzip.org/downloads.html下面下载源代码包即可,boost直接使用源代码来进行编译。
3. zlib
将zlib-1.2.7.zip解压到G:\boost_lib文件夹下。
zlib的主页是http://www.zlib.net/,从该网页下面下载源代码包即可,boost直接使用源代码来进行编译。
4. python
安装python。我的安装目录是C:\Python27;
python的主页是http://www.python.org/,下载安装即可。boost默认是会编译python,并且会自动寻找python的安装目录。
5. boost
boost_1_50_0.zip解压到 G:\boost_lib文件夹下;
三. 编译
1. 编译jam
启动Visual Studio 2008 Command Prompt , 进入 boost的解压目录,即G:\boost_lib\boost_1_50_0, 输入bootstrap,便在boost根目录下生成bjam.exe文件。
【 注:在网上看了许多教程,老版本需要进入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 ;
新建build.bat,脚本内容如下。放在boost根目录下,点击运行
【注:1.替换相应路径;2. 因为是完全编译,时间可能有点长,大家耐心等待。】。
REM used with iostream library
REM G:\boost_lib\boost_1_50_0\libs\iostreams\doc\installation.html
set BZIP2_SOURCE="G:\boost_lib\bzip2-1.0.6"
set ZLIB_SOURCE="G:\boost_lib\zlib-1.2.7"
REM used with regex library with unicode support
set ICU_PATH="G:\boost_lib\icu"
REM DLL版本
bjam --toolset=msvc-9.0 --prefix=G:\boost_lib\boost_1_50_0 --builddir=./ address-model=32 link=shared runtime-link=shared threading=multi install debug release
REM lib版本
bjam --toolset=msvc-9.0 --prefix=G:\boost_lib\boost_1_50_0 --builddir=./ address-model=32 link=static runtime-link=shared threading=multi install debug release
相应的参数说明请参考:http://hwcrazy.com/35cf4de6f1c011e08e40000d601c5586/3ca9f530f1c011e08e40000d601c5586/
编译好的文件放置在boost根目录的lib目录下(G:\boost_lib\boost_1_50_0\lib ),在boost根目录下的bin.v2目录是中间文件,编译后删除即可。
【注:如果仅需要使用boost的部分功能,就不需要完整编译, 例如:仅安装正则表达式库请参考 正则表达式 boost regexp的安装】
四. 在工程中添加boost
boost加入工程
添加包含文件:tools->options->project and solutions VC++目录(此处填写boost根目录,即 G:\boost_lib\boost_1_50_0 )
添加库文件:tools->options->project and solutions VC++目录(此处填写boost库目录,即 G:\boost_lib\boost_1_50_0 \lib )
测试代码:
#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;
}
return EXIT_SUCCESS;
}
debug:
配置完成, ok
更多汇总贴请参考:http://blog.csdn.net/chjp2046/article/details/5662691
总有一种方法适合你,呵呵