VS2010下安装和使用boost库

来源:互联网 发布:hadoop源码 编辑:程序博客网 时间:2024/05/17 22:36

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.zipboost_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 Editorhttp://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,请参考文章:

http://blog.csdn.net/misskissc/article/details/9793645

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
JeanieDebbieRickJohnAmandaMargaretBenjaminN };
int main()
{
        using namespace boost;
        const char *name[] = { "Jeanie""Debbie""Rick""John""Amanda",
               "Margaret""Benjamin"
        };
        adjacency_list <> g(N);
        add_edge(JeanieDebbieg);
        add_edge(JeanieRickg);
        add_edge(JeanieJohng);
        add_edge(DebbieAmandag);
        add_edge(RickMargaretg);
        add_edge(JohnBenjaming);
        graph_traits < adjacency_list <> >::vertex_iterator iend;
        graph_traits < adjacency_list <> >::adjacency_iterator aia_end;
        property_map < adjacency_list <>, vertex_index_t >::type
               index_map = get(vertex_indexg);
        for (boost::tie(iend) = vertices(g); i != end; ++i) {
               std::cout << name[get(index_map, *i)];
               boost::tie(aia_end) = adjacent_vertices(*ig);
               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配套使用》 

0 0
原创粉丝点击