boost在多平台下的安装

时间:2022-10-06 04:34:27

曾经给自己定下了一个宏伟的目标,想把cocos2dx的写一个教程;可惜...不说了,说多了都是泪啊,直接进入正题。

首先,不要问我boost是什么,因为我也不知道,“度娘”和“谷哥”在等你,嘿嘿。

一 Mac OS

Mac下面有两种安装方式都是很方便的,网上世纪也都给出来了,我也是站在巨人的肩上,然后对他的内容做个整理,仅此而已啦。

1 MacPorts安装

1.1 环境配置

MacPorts就是一个工具,不用深究下载安装就是啦(下载点我)。

咦,我安装好了怎么找不到?你找他搞毛线啊,看这里:打开终端-》输入:"sudo port install boost"-》按回车-》输入密码(密码是什么?你自己电脑的密码)-》然后等啊等...

1.2 工程配置

如何引用呢?用Xcdoe打开要使用boost的项目,然后在build setting中的Header Search Paths一栏,增加一个目录,填入"/opt/local/include",然后找到Library Search Paths一栏,填入"/opt/local/lib"搞定啦。

1.3 代码中使用

代码中使用就不多多少啦,主要是包含头文件的路径说一下:

#include <boost/scoped_ptr.hpp>
#include <boost/lexical_cast.hpp>

2 源代码安装

2.1 下载,官网去下载源代码,然后解压(附下载地址)。

2.2 使用终端cd到刚解压的文件夹下面 -》输入"./boostrap.sh",等到运行完成,将在文件夹下面生成bjam。

2.3 在终端输入:“./bjam”,然后静等十来分钟就搞定啦。

2.4 然后,如图配置项目:(话说这是哪位大神的图,我拿过来用用)。

boost在多平台下的安装

2.5 后面的使用不多说了,同上。


二 Win7下面

1.去www.boost.org下载最新的boost,我下载了boost_1_46_1.7z

2.(我放在E:/cpp目录下)解压到当前文件夹

3.打开VS2010->VS TOOLS->VS命令提示

4.CD E:/cpp/boost_1_46_1 

5.输入bootstrap,便生成bjam.exe文件

6.输入bjam toolset=msvc-10.0 variant=debug,release threading=multi link=static,便生成boost库(时间挺长20分钟以上)

7.修改VS2010的参数 在项目的组合显示那找到属性页,打开属性页,选择配置属性,选择VC++目录,设置includepath和libpath,

如我的为E:/cpp/boost_1_46_1;$(IncludePath)

E:/cpp/boost_1_46_1/stage/lib;$(LibraryPath)

8.运行如下代码测试:

#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;
}



传递正能量:能自得师者王,谓人莫己若者亡。好问则裕,自用者小。