您的位置:首页 > 其它

VS2010下安装和使用boost库

2014-03-07 11:09 316 查看
boost官网 http://www.boost.org/

boost sourceforge http://sourceforge.net/projects/boost/files/

Asio官网 http://think-async.com/
Asio sourceforge http://sourceforge.net/projects/asio/files/

Asio samples https://github.com/mabrarov/asio_samples

1.去官网www.boost.org下载最新的boost,我下载了boost_1_55_0.zip和boost_1_55_0-msvc-10.0-32.exe。前者是纯净的源码,需要用户自己编译;后者是VS2010已编译的,含源码和编译生成的库。

2.这里只讲诉boost_1_55_0-msvc-10.0-32.exe。安装路径不建议放在C盘,例如D:\tmpcode\boost_1_55_0。安装需要3.4GB硬盘空间。



3.设置Windows的环境变量。推荐使用工具Rapid Environment Editor。http://www.rapidee.com/
环境变量,用户变量组,新建变量名:BOOST,变量值:D:\tmpcode\boost_1_55_0



4.修改VS2010的参数,在项目的解决方案那里找到属性页,打开并选择配置属性,选择VC++目录,设置包含目录和库目录,例如我的为:
包含目录$(BOOST);$(IncludePath)
库目录 $(BOOST)\lib32-msvc-10.0;$(LibraryPath)



5.至此设置完毕。如果想自行编译源码boost_1_55_0.zip,请参考文章:
/article/1935303.html
6.运行下面程序,测试
#include "stdafx.h"

#include <boost/config.hpp>

#include <iostream>

#include <vector>

#include <string>

#include <boost/graph/adjacency_list.hpp>

#include <boost/tuple/tuple.hpp>

enum family

{ Jeanie, Debbie, Rick, John, Amanda, Margaret, Benjamin, N };

int main()

{

using namespace boost;

const char *name[] = { "Jeanie", "Debbie", "Rick", "John", "Amanda",

"Margaret", "Benjamin"

};

adjacency_list <> g(N);

add_edge(Jeanie, Debbie, g);

add_edge(Jeanie, Rick, g);

add_edge(Jeanie, John, g);

add_edge(Debbie, Amanda, g);

add_edge(Rick, Margaret, g);

add_edge(John, Benjamin, g);

graph_traits < adjacency_list <> >::vertex_iterator i, end;

graph_traits < adjacency_list <> >::adjacency_iterator ai, a_end;

property_map < adjacency_list <>, vertex_index_t >::type

index_map = get(vertex_index, g);

for (boost::tie(i, end) = vertices(g); i != end; ++i) {

std::cout << name[get(index_map, *i)];

boost::tie(ai, a_end) = adjacent_vertices(*i, g);

if (ai == a_end)

std::cout << " has no children";

else

std::cout << " is the parent of ";

for (; ai != a_end; ++ai) {

std::cout << name[get(index_map, *ai)];

if (boost::next(ai) != a_end)

std::cout << ", ";

}

std::cout << std::endl;

}

return EXIT_SUCCESS;

}


推荐姊妹篇《Linux系统编译boost源码,然后和Qt
Creator配套使用》
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: