vs2008安装boost库
2010年06月10日
首先我在晚上找到了很多的说明:我先一一罗列在下
************************************************** ******************************* [b]一。下载 [/b]
boost库2008年3月底发布了1.35.0版本,包括了12个新的库和若干对于新库的修正。请参见http://www.boost.org/users/news/version_1_35_0 来 获取详细的更新信息。
最大的喜讯就是提供了对于Visual Studio 2008编译器的支持(1.34也可以,但是需要手工修改)。
下载地址: http://www.boost.org/users/download/ boost JAM可以不用下载,源代码已经包括在boost库中,可以直接来编译出来。 [b]二。准备工作 [/b]
编译boost库之前,需要做一些准备工作。下载一些Open Source的包,来支持boost特定库的需要。 [b]1. ICU [/b]
ICU提供了unicode和国际化支持,目前的版本是3.8.1。ICU的主页是http://www.icu-project.org/ 。 [b](1). 下载 [/b]
可以从http://www.icu-project.org/download/3.8.html 下 载源代码版本和使用VS2005编译的版本。推荐下载源代码版本自己进行编译,以避免依赖于VS2005的运行时库。 [b](2). 编译 [/b]
ICU的编译比较简单,打开ICU源代码目录下的source\allinone\allinone.sln,需要转换到VS2008格式,直接转 换即可。然后,选择release,Rebuild Solution即可。
(3). 测试
将编译出来的bin目录加入到系统的PATH目录中去。然后,重新打开allinone.sln工程。
需要通过测试的项目 cintltst项目
intltest项目
iotest
分别设置成启动项目,运行即可。 [b]2. bzip [/b]
bzip的主页是 http://www.bzip.org/ ,从http://www.bzip.org/downloads.html 下 面下载源代码包即可,boost直接使用源代码来进行编译。 [b]3. zlib [/b]
zlib的主页是http://www.zlib.net/ ,从该网页下 面下载源代码包即可,boost直接使用源代码来进行编译。 [b]4. python [/b]
python的主页是http://www.python.org/ , 下载python的2.5.2版本,安装即可。boost默认是会编译python,并且会自动寻找python的安装目录。 [b]三。编译 [/b]
到开始菜单的VS2008菜单项下,启动Visual Studio 2008 Command Prompt,以下编译步骤均假定直接在该工具下进行编译。 [b]1. 编译jam [/b]
到tools\jam目录下面运行build_dist.bat,编译好的放在tools\jam\stage\boost-jam- 3.1.16-1-ntx86目录下,将bjam.exe复制到boost的根目录。 [b]2. 编译boost [/b]
鉴于参考2下使用build-type有问题,可以使用以下命令来分别编译dll版本和lib版本。下面是一个示例脚本的例子,其中的目录需要替 换:
1
REM used with iostream library 2
REM boost_1_35_0\libs\iostreams\doc\installation.html 3
4
set BZIP2_SOURCE="E:\library\bzip2-1.0.4" 5
set ZLIB_SOURCE="E:\library\zlib123" 6
7
REM used with regex library with unicode support 8
set ICU_PATH="E:\library\icu" 9
10
REM DLL版本 11
bjam --toolset=msvc --stagedir=./lib_x86 --builddir=./ address-model=32 link=shared runtime-link=shared threading=multi stage debug release 12
13
REM lib版本 14
bjam --toolset=msvc --stagedir=./lib_x86 --builddir=./ address-model=32 link=static runtime-link=shared threading=multi stage debug release 15
编译好的文件放置在boost根目录的lib_x86\lib目录下,在boost根目录下的bin.v2目录是中间文件,编译后删除即可。
如果需要去掉编译过程中的一些warning,可以在tools\build\v2的user-config.jam文件中加入以下这一行: using msvc : : : /wd4819 /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 ;
[b]四。参考文章 [/b]
1. vs2005下安装boost http://hi.baidu.com/vivid217/blog/item/8e484eafd3b 52ff8faed5063.html 2. boost1.35.0编译日志 ************************************************** ******************************* 网上有很多安装方法,以下是我成功安装的步骤
1.下载boost_1_34_1压缩文件,解压缩到d:\boost_1_34_1\目录下
2.编译bjam
从vs2005的工具菜单进入命令提示窗口(一定要从这进),cd到d:\boost_1_34_1\tools\jam\src下执行 build.bat,会在d:\boost_1_34_1\tools\jam\src\bin.ntx86\产生bjam.exe,将bjam.exe 复制到d:\boost_1_34_1\下。
3.设定编译环境
修改user-config.jam (d:\boost_1_34_1\tools\build\v2\user-config.jam) 的MSVC configuration
# MSVC configuration
# Configure msvc (default version, searched in standard location
# and PATH).
# using msvc ;
using msvc : 8.0 : : /wd4819 /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0;
4.编译boost ************************************************** ******************************* 一、下载Boost首先,我们到 http://www.boost.org去下载 boost1.38的代码包。得到一个压缩包boost_1_38_0.zip,你也可以选择下载其它格式的。
然后我们把它解压出来,我把它解压在D盘根目录下面:
二、获取编译工具首先,我们需要到bjam.exe这是一个用于编译的工具。
接 下来我将会在Visual Studio 2008 SP1简体中文专业版中编译Boost1.38。我们去开始菜单,使用管理员身份运行Visual Studio 2008 命令提示(非Vista请无视):
然后我们通过cd等DOS指令 进入到:
Setting environment for using Microsoft Visual Studio 2008 x86 tools.
C:\Windows\system32>d:
D:\>cd boost_1_38_0
D:\boost_1_38_0>cd tools
D:\boost_1_38_0\tools>cd jam
D:\boost_1_38_0\tools\jam>cd src
D:\boost_1_38_0\tools\jam\src>
然后我们在这个src目录下面执行build.bat:
D:\boost_1_38_0\tools\jam\src>build.bat
然后我们稍等一小会儿等待系统自动为我们生成编译工具。
生成完毕之后src目录下会出现一个bin.ntx86目录。进入这个目录会看见bjam.exe。
我们把这个bjam.exe拷贝到boost 1.38的根目录即我的D:\boost_1_38_0。
同上面的方法打开Visual Studio 2008 命令提示,进入D:\boost_1_38_0。通过如下命令我们就可以查看当前版本的Boost的哪些组件需要编译了,因为Boost大部分组件都是以模板的形式存在的,不需要编译:
D:\boost_1_38_0>bjam --show-libraries
The following libraries require building:
- date_time
- filesystem
- function_types
- graph
- iostreams
- math
- mpi
- program_options
- python
- regex
- serialization
- signals
- system
- test
- thread
- wave
三、编译Boost1.38
我们再去D盘根目录创建一个我们的目标安装文件夹:D:\BoostLib 1_38
接下来使用默认的方式将Boost1.38完整编译到目标文件夹:
D:\boost_1_38_0>bjam install --prefix="D:\BoostLib 1_38" debug
剩下的参数都用默认的了。敲下回车,好了,开始耐心等待编译完成吧。在此之前请确认您的D盘的剩余空间,要完整编译需要大约3G的剩余空间,主要是会生成很多临时文件,编译连接完之后我们 可以删除掉的。曾经在网上看到说需要12G的空间,编译需要好几个小时,可能是现在不一样了吧,呵呵,电脑配置越来越好了。而且整个编译过程也需要一定的时间,编译Debug版本大约需要40-80分钟不等,Release也差不多,根据不同的机器配置会有所不同,当然配 置越好越快啦。
编译的过程中会出现很多的Warning,你可以无视它们,基本上用于学习的目的,你很难很因为这些Warning而使得程序挂掉。
warning: No toolsets are configured.
warning: Configuring default toolset "msvc".
// 这里由于我们 没有选择编译器,所以这里默认选择了VC,由于我们是在Visual Studio 2008的命令提示下面,因此自动选择了VC9。VC2005也是同样的道理,我们选择VC2005的命令提示符就可以了。
warning: If the default is wrong, your build may not work correctly.
warning: Use the "toolset=xxxxx" option to override our guess.
warning: For more configuration options, please consult
编译的过程中会自动的帮你Copy一些诸如模板头文件等到目标文件夹去:
这个Copy过 程大约需要三分钟。完成之后便开始编译:
期间会有 一些警告,这些都可以无视。开始编译之后会在lib文件夹中出现相应的lib和dll文件, 并且由于时间的推移会越来越多,这至少说明您的编译过程正在进行中。而且在编译的过程中还会发生COPY行为。
大家可以看看Boost生成的这些Lib文 件,比如boost_regex-vc90-mt-gd-1_38.lib。它的命名很考究的。
boost代表这是boost库的组件
regex代表这个是正则表达式的库
VC90代表它是什么编译器版本
mt代表它支持多线程/ Multithreads
gd代表这是debug版本
1_38代表了Boost的版本号
是不是很有艺术感呢?
另外还有一些这样的Lib文件,比如libboost_iostreams-vc90-mt-gd-1_38.lib。它以libboost开头,这表示这些lib是静态库文件,属于静态连接的库文件。它们没有对应的dll文件。同时您也可以注意到它们都比只具备索引功能的lib大得多。跟动态库版本有啥区别不用我解释了吧?
O(∩_∩)O~
Debug版本编译完我生成了107个文件,你有多少个呢?
好了,接下来我们使用类似的步骤来编译Release版本的Boost:
Release版本的Lib和Dll的命名和Debug版本的差别就在于没有gd,比如:boost_math_c99f-vc90-mt-1_38.lib。
在等待了和编译Debug差不多的时间之后,我们的Boost就成功编译了。
为了符合我们通常SDK的习惯,我们把D:\BoostLib 1_38\include\boost-1_38\下面的boost目录全部拷贝到include目录下面,然后再把boost-1_38这个空的文件夹删除。
现在我们的所有头文件都在include文件夹下面了,保留boost文件夹只是为了符合boost的习惯;所有的lib和dll都位于lib文件夹下面。
四、配置IDE和删除临时文件
但是整个过程还没有结束,我们还需要配置IDE。打开Visual Studio 2008 SP1(其它VC开 发平台也类似),选择"工具",再选择"选项",然后在"项目和解决方案"下面选择vc++目录,在"包含目录"下面添加Boost的include路径:
在库文件下面添加Boost的lib路径:
现在Boost的安装目录已经膨胀到了1.04G:
源代码的目录,即D:\boost_1_38_0已经变得硕大无比,因为生成了大量的临时文件,我建议您删除该文件夹下面的bin.v2即可。
爽,编译完成,赶快来段代码,试试:
#include
#include
using namespacestd ;
using namespaceboost ;
int main ()
{
cout >strBirthday ;
try
{
gregorian ::datebirthday ( gregorian ::from_simple_string (strBirthday ) );
gregorian ::datetoday ( gregorian ::day_clock ::local_day () );
gregorian ::daysdays_alive = today - birthday ;
if ( days_alive Windows下编译开始讲解。
对于大部分Boost应用来说,它是不用编译的,直接包含头文件就可使用,如:
Java 代码 type="application/x-shockwave-flash" width="14" height="15" src="http://raylinn.javaeye.com/javascripts/syntax highlighter/clipboard_new.swf" src="http://raylinn.javaeye.com/javascripts/syntax highlighter/clipboard_new.swf" flashvars="clipboard=any%0Aarray%0Aasio%0Aconversi on%0Acrc%0Abind%2Fmem_fn%0Aenable_if%0Afunction%0Al ambda%0Ampl%0Asmart_pt%0A" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflash player" height="15" width="14">
Java 代码 type="application/x-shockwave-flash" width="14" height="15" src="http://raylinn.javaeye.com/javascripts/syntax highlighter/clipboard_new.swf" src="http://raylinn.javaeye.com/javascripts/syntax highlighter/clipboard_new.swf" flashvars="clipboard=date_time%0Afilesystem%0Afunc tion_types%0Agraph%0Aiostreams%0Amath%0Ampi%0Aprogr am_options%0Apython%0Aregex%0Aserialization%0Asigna ls%0Asystem%0Atest%0Athread%0Awave%0A" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflash player" height="15" width="14">
date_time filesystem function_types graph iostreams math mpi program_options python regex serialization signals system test thread wave
要完全编译boost库需要先准备一些第三方库:
1. Regex所需Unicode支持类库 -- ICU
编译ICU较为简单,解开ICU包之后,在其目录下可以找到一个叫"allinone"的目录,用Visual studio或者visual studio express打开里面的allinone.sln,选择release,即可以编译完成,编译之后,将include目录和release目录下的库文 件拷贝出来,分别放在C:\icu\include和C:\icu\lib.
2. Graph所需的Xml处理类库 --Expat , 将该自解压文件解压到C:\expat即可。
3.Boost.MPI所需MPI类库 -- Boost的官方站点说需要MPICH或OpenMPI之类的支持,事实上在Windows下总是会提示需要MPIC++,事实上你需要的是Microsoft Cluster Pack SDK ,下载并默认安装在c:\Program Files\Microsoft Compute Cluster Pack下。
现在完全编译Boost所需要的类库都准备好了。
下载Boost并解压到C:\boost.src,进入Visual studio prompt,然后运行boost.src目录下的bootstrap.bat,这个脚本会帮你生成编译所需的bjam.exe文件。
如果你机器上同时有多个不同版本的VC++存在,先修改project-config.jam,将
"using msvc ;"改为诸如" using msvc : 9.0 ;"
要支持mpi,你可以建立一个user-config.jam文件,然后添加一行"using mpi ;"即可
接下来的工作,我写了个小脚本boost.bat
Batch 代码 type="application/x-shockwave-flash" width="14" height="15" src="http://raylinn.javaeye.com/javascripts/syntax highlighter/clipboard_new.swf" src="http://raylinn.javaeye.com/javascripts/syntax highlighter/clipboard_new.swf" flashvars="clipboard=%40echo%20off%20%20%0A%40echo %20Making%20all%20Boost%20library%20--%20By%20Ray%2 0Linn%20%20%0Aset%20EXPAT_INCLUDE%3DC%3A%5Cexpat%5C source%5Clib%20%20%0Aset%20EXPAT_LIBPATH%3DC%3A%5Ce xpat%5Cbin%20%20%0Aset%20INCLUDE%3D%25INCLUDE%25%3B c%3A%5CProgram%20Files%5CMicrosoft%20Compute%20Clus ter%20Pack%5CInclude%3Bc%3A%5CProgram%20Files%5CMic rosoft%20Compute%20Cluster%20Pack%5CInclude%5Ci386% 3B%0Aset%20LIBPATH%3D%25LIBPATH%25%3Bc%3A%5CProgram %20Files%5CMicrosoft%20Compute%20Cluster%20Pack%5CL IB%5Ci386%3B%20%20%0A%0Aecho%20adding%20-a%20to%20f orce%20rebuild%0A%3Adebug%0A%0Abjam%20-s%20HAVE_ICU %3D1%20-s%20ICU_PATH%3DC%3A%5Cicu%20threading%3Dmul ti%20link%3Dstatic%20runtime-link%3Dshared%20varian t%3Ddebug%20--user-config%3D.%5Cuser-config.jam%20- -prefix%3D%22C%3A%5Cboost%22%20install%0A%0A%3Arele ase%0A%0Abjam%20-s%20HAVE_ICU%3D1%20-s%20ICU_PATH%3 DC%3A%5Cicu%20threading%3Dmulti%20link%3Dstatic%20r untime-link%3Dshared%20variant%3Drelease%20--user-c onfig%3D.%5Cuser-config.jam%20--prefix%3D%22C%3A%5C boost%22%20install%0A" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflash player" height="15" width="14">
@echo off
@echo Making all Boost library -- By Ray Linn
set EXPAT_INCLUDE=C:\expat\source\lib
set EXPAT_LIBPATH=C:\expat\bin
set INCLUDE=%INCLUDE%;c:\Program Files\Microsoft Compute Cluster Pack\Include;c:\Program Files\Microsoft Compute Cluster Pack\Include\i386;
set LIBPATH=%LIBPATH%;c:\Program Files\Microsoft Compute Cluster Pack\LIB\i386;
echo adding -a to force rebuild
:debug
bjam -s HAVE_ICU=1 -s ICU_PATH=C:\icu threading=multi link=static runtime-link=shared variant=debug --user-config=.\user-config.jam --prefix="C:\boost" install
:release
bjam -s HAVE_ICU=1 -s ICU_PATH=C:\icu threading=multi link=static runtime-link=shared variant=release --user-config=.\user-config.jam --prefix="C:\boost" install
@echo off @echo Making all Boost library -- By Ray Linn set EXPAT_INCLUDE=C:\expat\source\lib set EXPAT_LIBPATH=C:\expat\bin set INCLUDE=%INCLUDE%;c:\Program Files\Microsoft Compute Cluster Pack\Include;c:\Program Files\Microsoft Compute Cluster Pack\Include\i386; set LIBPATH=%LIBPATH%;c:\Program Files\Microsoft Compute Cluster Pack\LIB\i386; echo adding -a to force rebuild :debug bjam -s HAVE_ICU=1 -s ICU_PATH=C:\icu threading=multi link=static runtime-link=shared variant=debug --user-config=.\user-config.jam --prefix="C:\boost" install :release bjam -s HAVE_ICU=1 -s ICU_PATH=C:\icu threading=multi link=static runtime-link=shared variant=release --user-config=.\user-config.jam --prefix="C:\boost" install
编译后会得到debug和release两个版本的boost,至此Boost编译完成。现在我们开始配置visual studio以方便以后使用Boost类库。
先设置一个环境变量
Java 代码 type="application/x-shockwave-flash" width="14" height="15" src="http://raylinn.javaeye.com/javascripts/syntax highlighter/clipboard_new.swf" src="http://raylinn.javaeye.com/javascripts/syntax highlighter/clipboard_new.swf" flashvars="clipboard=set%20Boost%3DC%3A%5Cboost%0A " quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflash player" height="15" width="14">
set Boost=C:\boost
接着打开Visual studio的菜单 tools-->Options...->projects and solutions-->VC++ directories 如图添加Boost类库的头文件和库文件的路径。
下面这一小段代码用于测试设置是否正确:
C++代码 type="application/x-shockwave-flash" width="14" height="15" src="http://raylinn.javaeye.com/javascripts/syntax highlighter/clipboard_new.swf" src="http://raylinn.javaeye.com/javascripts/syntax highlighter/clipboard_new.swf" flashvars="clipboard=%23include%20%22stdafx.h%22%0 A%23include%20%3Ciostream%3E%0A%23include%20%3Citer ator%3E%0A%23include%20%3Calgorithm%3E%0A%23include %20%3Cstring%3E%0A%23include%20%3Cboost%2Fregex.hpp %3E%0A%0Aint%20_tmain(int%20argc%2C%20_TCHAR*%20arg v%5B%5D)%0A%7B%0A%09std%3A%3Astring%20line%3B%0A%09 static%20const%20boost%3A%3Aregex%20pat(%22%5ESubje ct%3A(Re%3A%7CAw%3A)*(.*)%22)%3B%0A%09while%20(std% 3A%3Acin)%0A%09%7B%0A%09%09std%3A%3Agetline(std%3A% 3Acin%2C%20line)%3B%0A%09%09boost%3A%3Asmatch%20mat ches%3B%0A%09%09if(boost%3A%3Aregex_match(line%2C%2 0matches%2C%20pat))%0A%09%09%09std%3A%3Acout%20%3C% 3C%20matches%5B2%5D%20%3C%3C%20std%3A%3Aendl%3B%0A% 09%7D%0A%7D%0A" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflash player" height="15" width="14">
#include "stdafx.h"
#include
#include
#include
#include
#include
int _tmain(int argc, _TCHAR* argv[])
{
std::string line;
static const boost::regex pat("^Subject:(Re:|Aw:)*(.*)");
while (std::cin)
{
std::getline(std::cin, line);
boost::smatch matches;
if(boost::regex_match(line, matches, pat))
std::cout #include #include #include #include int _tmain(int argc, _TCHAR* argv[]) { std::string line; static const boost::regex pat("^Subject:(Re:|Aw:)*(.*)"); while (std::cin) { std::getline(std::cin, line); boost::smatch matches; if(boost::regex_match(line, matches, pat)) std::cout << matches[2] << std::endl; } }
如无差错,这段代码应该可以正确编译并链接。这时候可以删除boost.src。
************************************************** ******************************* ************************************************** ******************************* ************************************************** ******************************* ************************************************** ******************************* ************************************************** *******************************
2010年06月10日
首先我在晚上找到了很多的说明:我先一一罗列在下
************************************************** ******************************* [b]一。下载 [/b]
boost库2008年3月底发布了1.35.0版本,包括了12个新的库和若干对于新库的修正。请参见http://www.boost.org/users/news/version_1_35_0 来 获取详细的更新信息。
最大的喜讯就是提供了对于Visual Studio 2008编译器的支持(1.34也可以,但是需要手工修改)。
下载地址: http://www.boost.org/users/download/ boost JAM可以不用下载,源代码已经包括在boost库中,可以直接来编译出来。 [b]二。准备工作 [/b]
编译boost库之前,需要做一些准备工作。下载一些Open Source的包,来支持boost特定库的需要。 [b]1. ICU [/b]
ICU提供了unicode和国际化支持,目前的版本是3.8.1。ICU的主页是http://www.icu-project.org/ 。 [b](1). 下载 [/b]
可以从http://www.icu-project.org/download/3.8.html 下 载源代码版本和使用VS2005编译的版本。推荐下载源代码版本自己进行编译,以避免依赖于VS2005的运行时库。 [b](2). 编译 [/b]
ICU的编译比较简单,打开ICU源代码目录下的source\allinone\allinone.sln,需要转换到VS2008格式,直接转 换即可。然后,选择release,Rebuild Solution即可。
(3). 测试
将编译出来的bin目录加入到系统的PATH目录中去。然后,重新打开allinone.sln工程。
需要通过测试的项目 cintltst项目
intltest项目
iotest
分别设置成启动项目,运行即可。 [b]2. bzip [/b]
bzip的主页是 http://www.bzip.org/ ,从http://www.bzip.org/downloads.html 下 面下载源代码包即可,boost直接使用源代码来进行编译。 [b]3. zlib [/b]
zlib的主页是http://www.zlib.net/ ,从该网页下 面下载源代码包即可,boost直接使用源代码来进行编译。 [b]4. python [/b]
python的主页是http://www.python.org/ , 下载python的2.5.2版本,安装即可。boost默认是会编译python,并且会自动寻找python的安装目录。 [b]三。编译 [/b]
到开始菜单的VS2008菜单项下,启动Visual Studio 2008 Command Prompt,以下编译步骤均假定直接在该工具下进行编译。 [b]1. 编译jam [/b]
到tools\jam目录下面运行build_dist.bat,编译好的放在tools\jam\stage\boost-jam- 3.1.16-1-ntx86目录下,将bjam.exe复制到boost的根目录。 [b]2. 编译boost [/b]
鉴于参考2下使用build-type有问题,可以使用以下命令来分别编译dll版本和lib版本。下面是一个示例脚本的例子,其中的目录需要替 换:
1
REM used with iostream library 2
REM boost_1_35_0\libs\iostreams\doc\installation.html 3
4
set BZIP2_SOURCE="E:\library\bzip2-1.0.4" 5
set ZLIB_SOURCE="E:\library\zlib123" 6
7
REM used with regex library with unicode support 8
set ICU_PATH="E:\library\icu" 9
10
REM DLL版本 11
bjam --toolset=msvc --stagedir=./lib_x86 --builddir=./ address-model=32 link=shared runtime-link=shared threading=multi stage debug release 12
13
REM lib版本 14
bjam --toolset=msvc --stagedir=./lib_x86 --builddir=./ address-model=32 link=static runtime-link=shared threading=multi stage debug release 15
编译好的文件放置在boost根目录的lib_x86\lib目录下,在boost根目录下的bin.v2目录是中间文件,编译后删除即可。
如果需要去掉编译过程中的一些warning,可以在tools\build\v2的user-config.jam文件中加入以下这一行: using msvc : : : /wd4819 /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 ;
[b]四。参考文章 [/b]
1. vs2005下安装boost http://hi.baidu.com/vivid217/blog/item/8e484eafd3b 52ff8faed5063.html 2. boost1.35.0编译日志 ************************************************** ******************************* 网上有很多安装方法,以下是我成功安装的步骤
1.下载boost_1_34_1压缩文件,解压缩到d:\boost_1_34_1\目录下
2.编译bjam
从vs2005的工具菜单进入命令提示窗口(一定要从这进),cd到d:\boost_1_34_1\tools\jam\src下执行 build.bat,会在d:\boost_1_34_1\tools\jam\src\bin.ntx86\产生bjam.exe,将bjam.exe 复制到d:\boost_1_34_1\下。
3.设定编译环境
修改user-config.jam (d:\boost_1_34_1\tools\build\v2\user-config.jam) 的MSVC configuration
# MSVC configuration
# Configure msvc (default version, searched in standard location
# and PATH).
# using msvc ;
using msvc : 8.0 : : /wd4819 /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0;
4.编译boost ************************************************** ******************************* 一、下载Boost首先,我们到 http://www.boost.org去下载 boost1.38的代码包。得到一个压缩包boost_1_38_0.zip,你也可以选择下载其它格式的。
然后我们把它解压出来,我把它解压在D盘根目录下面:
二、获取编译工具首先,我们需要到bjam.exe这是一个用于编译的工具。
接 下来我将会在Visual Studio 2008 SP1简体中文专业版中编译Boost1.38。我们去开始菜单,使用管理员身份运行Visual Studio 2008 命令提示(非Vista请无视):
然后我们通过cd等DOS指令 进入到:
Setting environment for using Microsoft Visual Studio 2008 x86 tools.
C:\Windows\system32>d:
D:\>cd boost_1_38_0
D:\boost_1_38_0>cd tools
D:\boost_1_38_0\tools>cd jam
D:\boost_1_38_0\tools\jam>cd src
D:\boost_1_38_0\tools\jam\src>
然后我们在这个src目录下面执行build.bat:
D:\boost_1_38_0\tools\jam\src>build.bat
然后我们稍等一小会儿等待系统自动为我们生成编译工具。
生成完毕之后src目录下会出现一个bin.ntx86目录。进入这个目录会看见bjam.exe。
我们把这个bjam.exe拷贝到boost 1.38的根目录即我的D:\boost_1_38_0。
同上面的方法打开Visual Studio 2008 命令提示,进入D:\boost_1_38_0。通过如下命令我们就可以查看当前版本的Boost的哪些组件需要编译了,因为Boost大部分组件都是以模板的形式存在的,不需要编译:
D:\boost_1_38_0>bjam --show-libraries
The following libraries require building:
- date_time
- filesystem
- function_types
- graph
- iostreams
- math
- mpi
- program_options
- python
- regex
- serialization
- signals
- system
- test
- thread
- wave
三、编译Boost1.38
我们再去D盘根目录创建一个我们的目标安装文件夹:D:\BoostLib 1_38
接下来使用默认的方式将Boost1.38完整编译到目标文件夹:
D:\boost_1_38_0>bjam install --prefix="D:\BoostLib 1_38" debug
剩下的参数都用默认的了。敲下回车,好了,开始耐心等待编译完成吧。在此之前请确认您的D盘的剩余空间,要完整编译需要大约3G的剩余空间,主要是会生成很多临时文件,编译连接完之后我们 可以删除掉的。曾经在网上看到说需要12G的空间,编译需要好几个小时,可能是现在不一样了吧,呵呵,电脑配置越来越好了。而且整个编译过程也需要一定的时间,编译Debug版本大约需要40-80分钟不等,Release也差不多,根据不同的机器配置会有所不同,当然配 置越好越快啦。
编译的过程中会出现很多的Warning,你可以无视它们,基本上用于学习的目的,你很难很因为这些Warning而使得程序挂掉。
warning: No toolsets are configured.
warning: Configuring default toolset "msvc".
// 这里由于我们 没有选择编译器,所以这里默认选择了VC,由于我们是在Visual Studio 2008的命令提示下面,因此自动选择了VC9。VC2005也是同样的道理,我们选择VC2005的命令提示符就可以了。
warning: If the default is wrong, your build may not work correctly.
warning: Use the "toolset=xxxxx" option to override our guess.
warning: For more configuration options, please consult
编译的过程中会自动的帮你Copy一些诸如模板头文件等到目标文件夹去:
这个Copy过 程大约需要三分钟。完成之后便开始编译:
期间会有 一些警告,这些都可以无视。开始编译之后会在lib文件夹中出现相应的lib和dll文件, 并且由于时间的推移会越来越多,这至少说明您的编译过程正在进行中。而且在编译的过程中还会发生COPY行为。
大家可以看看Boost生成的这些Lib文 件,比如boost_regex-vc90-mt-gd-1_38.lib。它的命名很考究的。
boost代表这是boost库的组件
regex代表这个是正则表达式的库
VC90代表它是什么编译器版本
mt代表它支持多线程/ Multithreads
gd代表这是debug版本
1_38代表了Boost的版本号
是不是很有艺术感呢?
另外还有一些这样的Lib文件,比如libboost_iostreams-vc90-mt-gd-1_38.lib。它以libboost开头,这表示这些lib是静态库文件,属于静态连接的库文件。它们没有对应的dll文件。同时您也可以注意到它们都比只具备索引功能的lib大得多。跟动态库版本有啥区别不用我解释了吧?
O(∩_∩)O~
Debug版本编译完我生成了107个文件,你有多少个呢?
好了,接下来我们使用类似的步骤来编译Release版本的Boost:
Release版本的Lib和Dll的命名和Debug版本的差别就在于没有gd,比如:boost_math_c99f-vc90-mt-1_38.lib。
在等待了和编译Debug差不多的时间之后,我们的Boost就成功编译了。
为了符合我们通常SDK的习惯,我们把D:\BoostLib 1_38\include\boost-1_38\下面的boost目录全部拷贝到include目录下面,然后再把boost-1_38这个空的文件夹删除。
现在我们的所有头文件都在include文件夹下面了,保留boost文件夹只是为了符合boost的习惯;所有的lib和dll都位于lib文件夹下面。
四、配置IDE和删除临时文件
但是整个过程还没有结束,我们还需要配置IDE。打开Visual Studio 2008 SP1(其它VC开 发平台也类似),选择"工具",再选择"选项",然后在"项目和解决方案"下面选择vc++目录,在"包含目录"下面添加Boost的include路径:
在库文件下面添加Boost的lib路径:
现在Boost的安装目录已经膨胀到了1.04G:
源代码的目录,即D:\boost_1_38_0已经变得硕大无比,因为生成了大量的临时文件,我建议您删除该文件夹下面的bin.v2即可。
爽,编译完成,赶快来段代码,试试:
#include
#include
using namespacestd ;
using namespaceboost ;
int main ()
{
cout >strBirthday ;
try
{
gregorian ::datebirthday ( gregorian ::from_simple_string (strBirthday ) );
gregorian ::datetoday ( gregorian ::day_clock ::local_day () );
gregorian ::daysdays_alive = today - birthday ;
if ( days_alive Windows下编译开始讲解。
对于大部分Boost应用来说,它是不用编译的,直接包含头文件就可使用,如:
Java 代码 type="application/x-shockwave-flash" width="14" height="15" src="http://raylinn.javaeye.com/javascripts/syntax highlighter/clipboard_new.swf" src="http://raylinn.javaeye.com/javascripts/syntax highlighter/clipboard_new.swf" flashvars="clipboard=any%0Aarray%0Aasio%0Aconversi on%0Acrc%0Abind%2Fmem_fn%0Aenable_if%0Afunction%0Al ambda%0Ampl%0Asmart_pt%0A" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflash player" height="15" width="14">
Java 代码 type="application/x-shockwave-flash" width="14" height="15" src="http://raylinn.javaeye.com/javascripts/syntax highlighter/clipboard_new.swf" src="http://raylinn.javaeye.com/javascripts/syntax highlighter/clipboard_new.swf" flashvars="clipboard=date_time%0Afilesystem%0Afunc tion_types%0Agraph%0Aiostreams%0Amath%0Ampi%0Aprogr am_options%0Apython%0Aregex%0Aserialization%0Asigna ls%0Asystem%0Atest%0Athread%0Awave%0A" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflash player" height="15" width="14">
date_time filesystem function_types graph iostreams math mpi program_options python regex serialization signals system test thread wave
要完全编译boost库需要先准备一些第三方库:
1. Regex所需Unicode支持类库 -- ICU
编译ICU较为简单,解开ICU包之后,在其目录下可以找到一个叫"allinone"的目录,用Visual studio或者visual studio express打开里面的allinone.sln,选择release,即可以编译完成,编译之后,将include目录和release目录下的库文 件拷贝出来,分别放在C:\icu\include和C:\icu\lib.
2. Graph所需的Xml处理类库 --Expat , 将该自解压文件解压到C:\expat即可。
3.Boost.MPI所需MPI类库 -- Boost的官方站点说需要MPICH或OpenMPI之类的支持,事实上在Windows下总是会提示需要MPIC++,事实上你需要的是Microsoft Cluster Pack SDK ,下载并默认安装在c:\Program Files\Microsoft Compute Cluster Pack下。
现在完全编译Boost所需要的类库都准备好了。
下载Boost并解压到C:\boost.src,进入Visual studio prompt,然后运行boost.src目录下的bootstrap.bat,这个脚本会帮你生成编译所需的bjam.exe文件。
如果你机器上同时有多个不同版本的VC++存在,先修改project-config.jam,将
"using msvc ;"改为诸如" using msvc : 9.0 ;"
要支持mpi,你可以建立一个user-config.jam文件,然后添加一行"using mpi ;"即可
接下来的工作,我写了个小脚本boost.bat
Batch 代码 type="application/x-shockwave-flash" width="14" height="15" src="http://raylinn.javaeye.com/javascripts/syntax highlighter/clipboard_new.swf" src="http://raylinn.javaeye.com/javascripts/syntax highlighter/clipboard_new.swf" flashvars="clipboard=%40echo%20off%20%20%0A%40echo %20Making%20all%20Boost%20library%20--%20By%20Ray%2 0Linn%20%20%0Aset%20EXPAT_INCLUDE%3DC%3A%5Cexpat%5C source%5Clib%20%20%0Aset%20EXPAT_LIBPATH%3DC%3A%5Ce xpat%5Cbin%20%20%0Aset%20INCLUDE%3D%25INCLUDE%25%3B c%3A%5CProgram%20Files%5CMicrosoft%20Compute%20Clus ter%20Pack%5CInclude%3Bc%3A%5CProgram%20Files%5CMic rosoft%20Compute%20Cluster%20Pack%5CInclude%5Ci386% 3B%0Aset%20LIBPATH%3D%25LIBPATH%25%3Bc%3A%5CProgram %20Files%5CMicrosoft%20Compute%20Cluster%20Pack%5CL IB%5Ci386%3B%20%20%0A%0Aecho%20adding%20-a%20to%20f orce%20rebuild%0A%3Adebug%0A%0Abjam%20-s%20HAVE_ICU %3D1%20-s%20ICU_PATH%3DC%3A%5Cicu%20threading%3Dmul ti%20link%3Dstatic%20runtime-link%3Dshared%20varian t%3Ddebug%20--user-config%3D.%5Cuser-config.jam%20- -prefix%3D%22C%3A%5Cboost%22%20install%0A%0A%3Arele ase%0A%0Abjam%20-s%20HAVE_ICU%3D1%20-s%20ICU_PATH%3 DC%3A%5Cicu%20threading%3Dmulti%20link%3Dstatic%20r untime-link%3Dshared%20variant%3Drelease%20--user-c onfig%3D.%5Cuser-config.jam%20--prefix%3D%22C%3A%5C boost%22%20install%0A" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflash player" height="15" width="14">
@echo off
@echo Making all Boost library -- By Ray Linn
set EXPAT_INCLUDE=C:\expat\source\lib
set EXPAT_LIBPATH=C:\expat\bin
set INCLUDE=%INCLUDE%;c:\Program Files\Microsoft Compute Cluster Pack\Include;c:\Program Files\Microsoft Compute Cluster Pack\Include\i386;
set LIBPATH=%LIBPATH%;c:\Program Files\Microsoft Compute Cluster Pack\LIB\i386;
echo adding -a to force rebuild
:debug
bjam -s HAVE_ICU=1 -s ICU_PATH=C:\icu threading=multi link=static runtime-link=shared variant=debug --user-config=.\user-config.jam --prefix="C:\boost" install
:release
bjam -s HAVE_ICU=1 -s ICU_PATH=C:\icu threading=multi link=static runtime-link=shared variant=release --user-config=.\user-config.jam --prefix="C:\boost" install
@echo off @echo Making all Boost library -- By Ray Linn set EXPAT_INCLUDE=C:\expat\source\lib set EXPAT_LIBPATH=C:\expat\bin set INCLUDE=%INCLUDE%;c:\Program Files\Microsoft Compute Cluster Pack\Include;c:\Program Files\Microsoft Compute Cluster Pack\Include\i386; set LIBPATH=%LIBPATH%;c:\Program Files\Microsoft Compute Cluster Pack\LIB\i386; echo adding -a to force rebuild :debug bjam -s HAVE_ICU=1 -s ICU_PATH=C:\icu threading=multi link=static runtime-link=shared variant=debug --user-config=.\user-config.jam --prefix="C:\boost" install :release bjam -s HAVE_ICU=1 -s ICU_PATH=C:\icu threading=multi link=static runtime-link=shared variant=release --user-config=.\user-config.jam --prefix="C:\boost" install
编译后会得到debug和release两个版本的boost,至此Boost编译完成。现在我们开始配置visual studio以方便以后使用Boost类库。
先设置一个环境变量
Java 代码 type="application/x-shockwave-flash" width="14" height="15" src="http://raylinn.javaeye.com/javascripts/syntax highlighter/clipboard_new.swf" src="http://raylinn.javaeye.com/javascripts/syntax highlighter/clipboard_new.swf" flashvars="clipboard=set%20Boost%3DC%3A%5Cboost%0A " quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflash player" height="15" width="14">
set Boost=C:\boost
接着打开Visual studio的菜单 tools-->Options...->projects and solutions-->VC++ directories 如图添加Boost类库的头文件和库文件的路径。
下面这一小段代码用于测试设置是否正确:
C++代码 type="application/x-shockwave-flash" width="14" height="15" src="http://raylinn.javaeye.com/javascripts/syntax highlighter/clipboard_new.swf" src="http://raylinn.javaeye.com/javascripts/syntax highlighter/clipboard_new.swf" flashvars="clipboard=%23include%20%22stdafx.h%22%0 A%23include%20%3Ciostream%3E%0A%23include%20%3Citer ator%3E%0A%23include%20%3Calgorithm%3E%0A%23include %20%3Cstring%3E%0A%23include%20%3Cboost%2Fregex.hpp %3E%0A%0Aint%20_tmain(int%20argc%2C%20_TCHAR*%20arg v%5B%5D)%0A%7B%0A%09std%3A%3Astring%20line%3B%0A%09 static%20const%20boost%3A%3Aregex%20pat(%22%5ESubje ct%3A(Re%3A%7CAw%3A)*(.*)%22)%3B%0A%09while%20(std% 3A%3Acin)%0A%09%7B%0A%09%09std%3A%3Agetline(std%3A% 3Acin%2C%20line)%3B%0A%09%09boost%3A%3Asmatch%20mat ches%3B%0A%09%09if(boost%3A%3Aregex_match(line%2C%2 0matches%2C%20pat))%0A%09%09%09std%3A%3Acout%20%3C% 3C%20matches%5B2%5D%20%3C%3C%20std%3A%3Aendl%3B%0A% 09%7D%0A%7D%0A" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflash player" height="15" width="14">
#include "stdafx.h"
#include
#include
#include
#include
#include
int _tmain(int argc, _TCHAR* argv[])
{
std::string line;
static const boost::regex pat("^Subject:(Re:|Aw:)*(.*)");
while (std::cin)
{
std::getline(std::cin, line);
boost::smatch matches;
if(boost::regex_match(line, matches, pat))
std::cout #include #include #include #include int _tmain(int argc, _TCHAR* argv[]) { std::string line; static const boost::regex pat("^Subject:(Re:|Aw:)*(.*)"); while (std::cin) { std::getline(std::cin, line); boost::smatch matches; if(boost::regex_match(line, matches, pat)) std::cout << matches[2] << std::endl; } }
如无差错,这段代码应该可以正确编译并链接。这时候可以删除boost.src。
************************************************** ******************************* ************************************************** ******************************* ************************************************** ******************************* ************************************************** ******************************* ************************************************** *******************************