原文出处:http://blog.sina.com.cn/s/blog_6e0693f70100txlg.html
其他参考:
http://www.cnblogs.com/wondering/archive/2009/05/21/boost_setup.html
Boost库是一个经过千锤百炼、可移植、提供源代码的C++库,作为标准库的后备,是C++标准化进程的发动机之一。 Boost库由C++标准委员会库工作组成员发起,在C++社区中影响甚大,其成员已近2000人。本文主要介绍了如何安装及使用Boost 1.47.0。
参考网页:
http://tech.ddvip.com/2009-05/1242887529120322.html
1). 在
http://www.boost.org/users/download/
下载最新版Boost库。解压后将其复制到指定位置。
2). 打开Visual Studio Command Prompt,进入解压后的Boost目录。输入bootstrap,等待其生成Boost构建工具bjam。
3). 在命令行输入bjam toolset=msvc-10.0 variant=debug,release threading=multi link=static
。然后等待安装完成。如果要生成64位库,键入命令bjam toolset=msvc-10.0 variant=debug,release threading=multi link=static address-model=64。
4). 安装完成后,屏幕上会提示"The Boost C++ Libraries were successfully built!"。并制定头文件和库文件目录。
5). 新建一个win32控制台程序,命名为Boost_Test。代码后附。
6). 在Project -> Boost_Test Properties -> Configuration Properties -> C/C++ -> General -> Additional Include Directories 中增加头文件路径。
7). 在Project -> Boost_Test Properties -> Configuration Properties -> Linker -> General -> Additional Library Directories 中增加库文件路径。这里我们不用制定需要链接的静态库,Boost会自动加载需要的库文件。
8). 编译,链接,测试结果如下。
Boost_Test.cpp代码
// Boost_Test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <boost/shared_ptr.hpp>
#include <boost/regex.hpp>
using namespace std;
struct Hello
{
Hello()
{
cout << "Hello constructor" << endl;
}
~Hello()
{
cout << "Hello destructor" << endl;
cin.get();
}
};
int _tmain(int argc, _TCHAR* argv[])
{
boost::regex regex("^(Hello|Bye) Boost$");
boost::cmatch helloMatches;
boost::regex_search("Hello Boost", helloMatches, regex);
cout << "The word between () is: " << helloMatches[1] << endl;
boost::shared_ptr<Hello> sharedHello(new Hello);
cin.get();
return 0;
}
Snowwolf_Yang注:
VC2010编译提示 LINK : fatal error LNK1104: 无法打开文件“libboost_system-vc100-mt-gd-1_51.lib”
这个错误应该是lib路径没写对:/stage/lib
项目\属性\配置属性\清单工具\输入和输出\嵌入清单:原来是“是”,改成“否”。
和
项目->属性->配置属性->C/C++ -> 预处理器 -> 预处理器定义,增加_CRT_SECURE_NO_DEPRECATE