VS2005使用boost库教程

今天弄了一天,总结一下。

(1)Boost的下载

Boost库的下载,官网(www.boost.org),其中在windows下的安装教程网址在http://www.boost.org/doc/libs/1_48_0/more/getting_started/windows.html#vs-header-only

(2)需要注意的问题

It's important to note the following:

a. The path to the boost rootDirectory (often C:\Program Files\boost\boost_1_48_0) issometimes referred to as $BOOST_ROOT in documentation and mailinglists .

b. To compile anything in Boost, you need a directory containingthe boost\ subdirectory in your #include path. Specificsteps for setting up #include paths in Microsoft Visual Studio followlater in this document; if you use another IDE, please consult your product'sdocumentation for instructions.

c. Since all of Boost's header files havethe .hpp extension, and live in the boost\subdirectory of theboost root, your Boost #include directives will look like:

#include <boost/whatever.hpp>

or

#include "boost/whatever.hpp"

depending on your preference regarding theuse of angle bracket includes. Even Windows users can (and, for portabilityreasons, probably should) use forward slashes in #includedirectives; yourcompiler doesn't care.

d. Don't be distracted by the doc\ subdirectory; it onlycontains a subset of the Boost documentation. Startwith libs\index.html if you're looking for the whole enchilada.

(3)head-only

       Boost库大部分组件不需要编译,直接包含头文件就可以了. 需要独立编译的库文件有下面这些

Boost.Filesystem

Boost.GraphParallel

Boost.IOStreams

Boost.MPI

Boost.ProgramOptions

Boost.Python 

Boost.Regex

Boost.Serialization

Boost.Signals

Boost.System

Boost.Thread

Boost.Wave

还有一些可选的。。。没有列出来

由于直接包含的比较简单,所以不进行详细的解说了,下面开始介绍如何使用需要独立编译的库,例如boost::regex

(4)需要独立编译的库的安装顺序

第一步:下载boost安装包,

boost_1_48_0,解压到任意文件夹下面,打开vs2005的 command prompt,并进入到boost文件夹下面,输入以下两个命令:

Bootstrap

.\b2

第二步:安装Boost.Build

(1)Go to thedirectory tools\build\v2\.

(2)Run bootstrap.bat

(3)Run b2install --prefix=PREFIX where PREFIX is the directory whereyou want Boost.Build to be installed

(4)Add PREFIX\bin toyour PATH environment variable.

第三步:调用b2

       切换到Boost目录下面,

b2 --build-dir=build-directory  toolset=toolset-name  --build-type=complete stage

例如:

C:\WINDOWS> cd C:\Program Files\boost\boost_1_48_0

C:\Program Files\boost\boost_1_48_0> b2 ^

More? --build-dir="C:\Documents andSettings\dave\build-boost" ^

More? --build-type=complete (msvc stage)

第四步:按照编译完的显示,将d:/boost_1_48加入到Include文件中,并且将d:/boost_1_48/stage/lib加入到Linker的lib的指定路径中。

第五步:测试

#include <cstdlib>

#include <stdlib.h>

#include <boost/regex.hpp>

#include <string>

#include <iostream>

 

using namespace std;

using namespace boost;

 

regex expression("^select ([a-zA-Z]*) from ([a-zA-Z]*)");

 

int main(int argc, char* argv[])

{

    std::string in;

    cmatch what;

    cout << "entertest string" << endl;

    getline(cin,in);

    if(regex_match(in.c_str(),what, expression))

    {

           for(inti=0;i<what.size();i++)

                  cout<<"str:"<<what[i].str()<<endl;

    }

    else

    {

           cout<<"ErrorInput"<<endl;

    }

    system("pause");

    return 0;

}

如果能过顺利编译过,表示正确安装了。哈哈。

可以查看b2 --show-libraries


你可能感兴趣的:(VS2005使用boost库教程)