Windows 7 64bit和Visual Studio 2010下安装及使用Boost 1.47.0
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。
![Windows <wbr>7 <wbr>64bit和Visual <wbr>Studio <wbr>2010下安装及使用Boost <wbr>1.47.0 Windows <wbr>7 <wbr>64bit和Visual <wbr>Studio <wbr>2010下安装及使用Boost <wbr>1.47.0](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_ub_lcx9RdNQdOhZa1cTUe6OBCY_u0aTTJJS2NFQbMXNo6nQvq96ttTZoWYxyFHsebzp170gOnoTjz8Pj8bDXIEztLBfRN-KGfr1zu-n0JKzD6h0wp2Yr0=s0-d)
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。![Windows <wbr>7 <wbr>64bit和Visual <wbr>Studio <wbr>2010下安装及使用Boost <wbr>1.47.0 Windows <wbr>7 <wbr>64bit和Visual <wbr>Studio <wbr>2010下安装及使用Boost <wbr>1.47.0](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_vUiQj5rQJG7vAIYF1wT_-MUsmktLKry0FSrWCx3hqDjRv9SLRDsdPWVAUyz9ocVJilW5DW_ivmKbHa-PHy10Pw_loHHrKHH84paLbDYfCwX5DmL9YHmmox=s0-d)
4). 安装完成后,屏幕上会提示"The Boost C++ Libraries were successfully built!"。并制定头文件和库文件目录。![Windows <wbr>7 <wbr>64bit和Visual <wbr>Studio <wbr>2010下安装及使用Boost <wbr>1.47.0 Windows <wbr>7 <wbr>64bit和Visual <wbr>Studio <wbr>2010下安装及使用Boost <wbr>1.47.0](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_vB5ihsyjd4GkhSqRqcmLfug6VbD9NswbeORDeNlRJfkH_PjTenckApHS0FsqQrwJ3bZgskDoKCiwCi2XjhWlNqC1kMZljf2qqUP2E-0-C6b6lEfhWXoWih=s0-d)
5). 新建一个win32控制台程序,命名为Boost_Test。代码后附。
6). 在Project -> Boost_Test Properties -> Configuration Properties -> C/C++ -> General -> Additional Include Directories 中增加头文件路径。![Windows <wbr>7 <wbr>64bit和Visual <wbr>Studio <wbr>2010下安装及使用Boost <wbr>1.47.0 Windows <wbr>7 <wbr>64bit和Visual <wbr>Studio <wbr>2010下安装及使用Boost <wbr>1.47.0](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_sF88PTaNTkC62NgHsog1zHxZVvTjjsieNPWS2Hoq-JdzXXYAEWSDGMYQH-VxgS85Q_0C9eMX__LCCcPMHKy9fBRkas46hM3ABNvtY9IaN9njleGkVP6cas=s0-d)
7). 在Project -> Boost_Test Properties -> Configuration Properties -> Linker -> General -> Additional Library Directories 中增加库文件路径。这里我们不用制定需要链接的静态库,Boost会自动加载需要的库文件。![Windows <wbr>7 <wbr>64bit和Visual <wbr>Studio <wbr>2010下安装及使用Boost <wbr>1.47.0 Windows <wbr>7 <wbr>64bit和Visual <wbr>Studio <wbr>2010下安装及使用Boost <wbr>1.47.0](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_si09tBh4_ypmpBoI1Ow-J8E1G0FTSFu5XJEm8ZmTHY5c1HMEZW0KdM9vgRYi55X2kKz1EGCHQjXST4q-PvkZbbjob5wtSlX1QHP3aFVPJX_r0pVyF5ZrZR=s0-d)
8). 编译,链接,测试结果如下。
![Windows <wbr>7 <wbr>64bit和Visual <wbr>Studio <wbr>2010下安装及使用Boost <wbr>1.47.0 Windows <wbr>7 <wbr>64bit和Visual <wbr>Studio <wbr>2010下安装及使用Boost <wbr>1.47.0](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_vjSt7o-Rz__G7HoEjKAdPOinPkRKbvUXn_TWHslz_XdHFy5v4Oz0HHpdRB7cwEmtNEwjYD_uveD26eQH-93oZDCCnDZZDaWFbkJmmvrmbIJnJg4IADX-se=s0-d)
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;
}
参考网页:http://tech.ddvip.com/2009-05/1242887529120322.html
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
{
};
int _tmain(int argc, _TCHAR* argv[])
{
}
沒有留言:
張貼留言