1下载
官方网站: www.boost.org 按照连接到sourceforge指定地方下载
小窍门: 一般国内的ftp上都会有,所以不一定需要浪费时间和金钱去外网上下载。
比如,我download boost_1_33_1.zip 就是用sf搜到了中科大的一个ftp直接下载的。
2安装
我目前只是在window机器上使用了一下。
解压后,
需要设置两个地方。
第一,执行tools/build/jam_src 下的build.bat,会生成/bin.ntx86/bjam.exe,将bjam.exe拷贝到你的boost库的根目录下,在命令行下执行之。过程有点长,plz wait! 另外,因为它默认对多种编译器都同时进行了配置,所以如果你没有装一些编译器的话,会看到屏幕上会打印出很多系统找不到指定目录的信息,没关系。比如,我只装了VC6,所以会打印很多找不到VC7的信息。
第二,设置编译器查找库文件路径的地方,比如VC6中, tools->option->directory, 加入你的boost库根路径就可以了
3 试用
from: dozb的程序人生
4 说明
做到以上几步,恭喜您,大部分Boost库就可以用了。
为什么不是全部?首先,目前还没有一个能完全符合C++标准的编译器,所以Boost库中的组件或多或少不可用,详细信息请看Boost网站上“编译器支持情况(Compiler Status)”一文。另外,有些库需要Build相应的lib或dll文件。不过这样的库很少,主要是由于平台相关性的原因,如处理正则表达式的regex库、支持python语言的python库等,而建构库的过程相当烦琐,需要使用Jam工具(可以简单提一下:在tools/build/jam_src/builds目录下有三个文件win32-borlandc.mk、win32-gcc.mk、win32-visualc.mk,分别是适用于Windows平台下的Borland C++ Compiler、GNU C++和Visual C++的mak文件。如果在Unix平台,则应使用tools/build/Makefile。用命令行工具make或nmake来做出Jam执行文件,然后再用Jam来建构库,详细内容可见Boost.Build文档)。我个人的建议是,不用急着去建构lib或dll。真的需要使用这些库时,再make随库提供的mak文件即可。虽然Boost.Jam也许是Boost库未来发展的方向,不过毕竟绝大部分库都无须建构,可以直接使用。
5. regex库的安装,试用
先看看regex自带的文档对于MIcrosoft VC 编译器安装的描述
You need version 6 of MSVC to build this library. If you are using VC5 then you may want to look at one of the previous releases of this library
Open up a command prompt, which has the necessary MSVC environment variables defined (for example by using the batch file Vcvars32.bat installed by the Visual Studio installation), and change to the /libs/regex/build directory.
Select the correct makefile - vc6.mak for "vanilla" Visual C++ 6 or vc6-stlport.mak if you are using STLPort.
Invoke the makefile like this:
nmake -fvc6.mak
You will now have a collection of lib and dll files in a "vc6" subdirectory, to install these into your development system use:
nmake -fvc6.mak install
The lib files will be copied to your /lib directory and the dll files to /bin, where is the root of your Visual C++ 6 installation.
You can delete all the temporary files created during the build (excluding lib and dll files) using:
nmake -fvc6.mak clean
Finally when you use regex++ it is only necessary for you to add the root directory to your list of include directories for that project. It is not necessary for you to manually add a .lib file to the project; the headers will automatically select the correct .lib file for your build mode and tell the linker to include it.
Note that if you want to dynamically link to the regex library when using the dynamic C++ runtime, define BOOST_REGEX_DYN_LINK when building your project.
If you want to add the source directly to your project then define BOOST_REGEX_NO_LIB to disable automatic library selection.
There are several important caveats to remember when using boost.regex with Microsoft's Compiler:
* There have been some reports of compiler-optimization bugs affecting this library, (particularly with VC6 versions prior to service patch 5) the workaround is to build the library using /Oityb1 rather than /O2. That is to use all optimization settings except /Oa. This problem is reported to affect some standard library code as well (in fact I'm not sure if the problem is with the regex code or the underlying standard library), so it's probably worthwhile applying this workaround in normal practice in any case. * If you have replaced the C++ standard library that comes with VC6, then when you build the library you must ensure that the environment variables "INCLUDE" and "LIB" have been updated to reflect the include and library paths for the new library - see vcvars32.bat (part of your Visual Studio installation) for more details. * If you are building with the full STLPort v4.x, then use the vc6-stlport.mak file provided and set the environment variable STLPORT_PATH to point to the location of your STLPort installation (Note that the full STLPort libraries appear not to support single-thread static builds). * If you are building your application with /Zc:wchar_t then you will need to modify the makefile to add /Zc:wchar_t before building the library.
先做一点试试,我的平台还是windows 2003+ VC6.0
step1: 找到文件vcvars32.bat ,备用
step2: 打开一个cmd窗口,并把路径切换到我的boost库目录下的 /libs/regex/build 子目录,找到vc6.mak文件
step3: 运行 'nmake -fvc6.mak ' ,错误提示: Error MSVCDIR 变量没有指定! 解决办法:在vcvars32.bat中找到
类似"set MSVCDir=C:/PROGRA~1/MICROS~2/VC98" 的一行,拷贝等号后面的路径。用UE打开vc6.mak文件
在前面点的位置 定义怎么一行"MSVCDIR = C:/PROGRA~1/MICROS~2/VC98"。 把这个新的mak文件另存为vc6_new.mak
step 4: 运行 'nmake -fvc6_new.mak ' , 然后便会产生所需的库文件等
step5: 运行 'nmake -fvc6_new.mak install' ,就会自动将regex库文件拷贝到 MSVCDIR 指定的目录下的相关目录下(如/bin,/libs等)
这样就 基本搞定了。关于什么regex++,我还没有试过。
试用
现在找到regex程序小试一下:
实现一个简单的split功能
#include
#include
#include
using namespace std;
unsigned tokenise(std::list
{
return boost::regex_split(std::back_inserter(l), s);
}
int main()
{
string s = "i am a boy!";
list
unsigned result = tokenise(l, s);
cout << result << " tokens found" << endl;
while(l.size())
{
s = *(l.begin());
l.pop_front();
cout << s << endl;
}
return 0;
}
运行成功!