c++ boost 安装

   在这里向大家介绍一下 c++ boost 的安装。我是在cygwin的环境下进行安装的。如果用vs等,大致方法一样

    1.首先我们需要download boost文件。可在http://www.boost.org/users/history/version_1_49_0.html里下载。下载完后我们需要对其解压 tar --bzip2 -xf /path/to/boost_1_49_0.tar.bz2

     2我们解压后得到目录,大概如下:

boost_1_49_0/ .................The “boost root directory”
   index.htm .........A copy of www.boost.org starts here
   boost/ .........................All Boost Header files
   
   libs/ ............Tests, .cpps, docs, etc., by library
     index.html ........Library documentation starts here
     algorithm/
     any/
     array/
                     …more libraries…
   status/ .........................Boost-wide test suite
   tools/ ...........Utilities, e.g. Boost.Build, quickbook, bcp
   more/ ..........................Policy documents, etc.
   doc/ ...............A subset of all Boost library docs

我们要用到的头文件目录放在boost里面。在这里简单的介绍一下boost里面的目录:boost library 文件存放的位置并不统一,但是遵循下面几个模型:一、一些旧的libraries 和大多数小的libraries是直接放在boost目录下的。二、大多数libraries的公共头文件是放在boost中子文件的。三、一些libraries是有一个“aggregate header”(在这称其为合集吧),包含其他所有的libraries header,如boost/pyton.hpp。四、大多数libraries在子目录下放着自己的私有头文件。这子目录叫detail或aux/.

    3介绍上面的文件目录,主要是想向大家说明boost 一个主要特征:他是一个 header-only libraries。这就意味这我们不需要编译boost libraries就可以直接用,只需要包含他们的header即可。但是有一些boost libraries是必须要生成lib的

•Boost.Filesystem
 •Boost.GraphParallel
 •Boost.IOStreams
 •Boost.MPI
 •Boost.ProgramOptions
 •Boost.Python (see the Boost.Python build documentation before building and installing it)
 •Boost.Regex
 •Boost.Serialization
 •Boost.Signals
 •Boost.System
 •Boost.Thread
 •Boost.Wave

  4如果我们是用的那些header-only,我们只需要向下面这样用即可

#include <boost/lambda/lambda.hpp>
#include <iostream>
#include <iterator>
#include <algorithm>

int main()
{
    using namespace boost::lambda;
    typedef std::istream_iterator<int> in;

    std::for_each(
        in(std::cin), in(), std::cout << (_1 * 3) << " " );
}

Now, in the directory where you saved example.cpp, issue the following command:

c++ -I path/to/boost_1_49_0 example.cpp -o example
我们应该用c++而不要使用gcc,如果要用gcc的话 需要在加上-lstdc++

编译玩了之后可以在console上输入echo 1 2 3 | ./example 查看一下效果

  5 如果我们要使用 library binary。我们可以使用简易安装在path/to/boost_1_49_0目录下运行./bootstrap.sh --help我们可以看到一些帮助文档

./bootstrap.sh --prefix=path/to/installation/prefix然后运行

$ ./b2 install

我们可以通过bootstrap.sh或者b2来定制自己需要的库。他们都是通过--show-libraries 来查看都有那些library通过 --with-libraries=library-name-list options来定制自己的library

到这里我们的boost安装也就完成啦。我们可以选择自己喜欢的方式来使用boost啦。

其他详细内容可以参考http://www.boost.org/doc/libs/1_49_0/more/getting_started/unix-variants.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值