VS2010 安装 Boost 库 1.54

Boost库被称为C++准标准库, 功能很是强大, 下面记录我在VS2010中安装使用Boost库的过程.

首先上官网http://www.boost.org/下载最新的Boost库, 我的版本是1_54_0版本, 解压下载的文件到任一文件夹, 

我放D盘boost目录下. 之后开始-运行-cmd打开dos窗口, 进入到boost库根目录下, 使用如下命令

cd D:oostoost_1_54_0

boost库中有一部分可以不需要编译就可以使用, 因为其功能直接在头文件使用模板和inline函数实现, 具体哪些

可以查看文档, 另外一部分则需要编译成外部库使用. 编译方法如下(官方文档中提供的方法): 

执行下面两条命令:

bootstrap
.2

第一条命令是准备boost编译环境, 第二条命令是编译boost库. 第二条命令则是编译, 其参数可以查看这里Boost.Build documentation.

编译过程比较慢, 20分钟以上, 慢慢等待. 编译之后的boost文件夹大概有2个多G.


在VS2010中使用boost也很简单, 下面是使用方法:

1、Properties > C/C++ > General > Additional Include Directories这里设定包含头文件的路径

例如:D:oostoost_1_54_0(到Boost目录的上一级)

2、Properties > C/C++ > Precompiled Headers,:Not Using Precompiled Headers:禁用头文件

3、Properties > Linker > General > Additional Library Directories添加包含的库目录

例如:D:oostoost_1_54_0stagelib

验证是否安装成功请新建工程example, 设置好属性后编译下面的程序:

#include <boost/regex.hpp>
#include <iostream>
#include <string>

int main()
{
    std::string line;
    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;
    }
}


然后将下面的内容保存为test.txt测试文件

To: George Shmidlap
From: Rita Marlowe
Subject: Will Success Spoil Rock Hunter?
---
See subject.

在dos窗口执行编译好的.exe文件, 将test.txt文本内容重定向为输入.

pathtocompiledexample < pathto	est.txt

如果输出如下:

Will Success Spoil Rock Hunter?

则表示安装成功. Good Luck!

原文地址:https://www.cnblogs.com/javawebsoa/p/3198962.html