vs2010配备boost编程环境

来源:互联网 发布:c语言疯狂讲义 v4.0 编辑:程序博客网 时间:2024/04/27 19:40

vs2010配置boost编程环境

第一步:下载boost,我下载的方法是从http://www.boost.org/上找最新的下载。名字叫boost_1_53_0。

 

第二步:在D盘,解压文件

 

第三步:开始->程序->MicrosoftVisual Studio 2010->Visual Studio Tools->Visual Studio 命令提示(2010),打开一个控制台。(也可以开始->cmd)

 

第四步:cd d:\boost_1_53_0

 

第五步:bootstrap.bat

 

第六步:b2--toolset=msvc-10.0 --build-type=complete stage    

                如果只有一个vs的话,可以直接执行b2命令就可以了。上面的命令指定了适用的vs版本为2010,编译方式为完全编译

 

测试:

第一步:创建一个工程,导入相应库

注:在2010环境下这步,在项目-->右键属性-->Configuration Properties中去填写对应路径

这两步我的配置的时候是VC++ Directories中: Include Directories: D:\boost_1_53_0   ,Library Directories:D:\boost_1_53_0\stage\lib

Linker->General中:Additional Library Directories:D:\boost_1_53_0\stage\lib

第二步:编写代码测试。

注:如果编写的测试代码出现类似错误”无法打开包括文件:“boost/regex.hpp”: No such file or directory” 说明附件包含目录出现错误,这时要纠正包含目录。

如果在下还有incude目录,我们只需包含includes目录就加载了相关头文件,如果没有,如上加载总目录,让编译器自己找。

附加:据说在第六步的时候,如果将执行指令里面的“stage”改成”install”,则会生成include指令。

 附加测试代码:

 C++ Code 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

#include<iostream>
#include <boost/regex.hpp>
using namespace std;

int main()
{
    // 3 digits, a word, any character, 2 digits or "N/A", 
    // a space, then the first word again
    boost::regex reg("\\d{3}([a-zA-Z]+).(\\d{2}|N/A)\\s\\1");

    std::string correct="123Hello N/A Hello";
    std::string incorrect="123Hello 12 hello";

    assert(boost::regex_match(correct,reg)==true);
    assert(boost::regex_match(incorrect,reg)==false);
    cout<<"Hello Boost !"<<endl;
}

如果输出结果为:


则表明boost库在vs2010下配置成功。


本文转自:JohnnyHu90的博客

0 0
原创粉丝点击