Linux下编译安装boost库

  1. 官网下载
    https://dl.bintray.com/boostorg/release/1.67.0/source/boost_1_67_0.tar.gz

  2. 解压: tar zxvf boost_1_67_0.tar.gz

  3. 进入目录: cd boost_1_67_0.tar.gz

  4. 执行命令:

    ./bootstrap.sh --with-libraries=all --with-toolset=gcc

    -–with-libraries 指定编译哪些boost库,all的话就是全部编译,只想编译部分库的话就把库的名称写上,之间用 , 号分隔即可

    -–with-toolset指定编译时使用哪种编译器,Linux下使用gcc即可

  5. 执行完毕看到以下内容即为成功

    Building Boost.Build engine with toolset gcc... tools/build/src/engine/bin.linuxx86_64/b2
    Detecting Python version... 2.6
    Detecting Python root... /usr
    Unicode/ICU support for Boost.Regex?... not found.
    Generating Boost.Build configuration in project-config.jam...
    
    Bootstrapping is done. To build, run:
    
       ./b2
    
    To adjust configuration, edit 'project-config.jam'.
    Further information:
    
      - Command line help:
        ./b2 --help
    
      - Getting started guide: 
        http://www.boost.org/more/getting_started/unix-variants.html
    
      - Boost.Build documentation:
        http://www.boost.org/build/doc/html/index.html
  6. 编译: ./b2 toolset=gcc

  7. 安装: sudo ./b2 install --prefix=/usr

    -–prefix=/usr用来指定boost的安装目录,不加此参数的话默认的头文件在/usr/local/include/boost目录下,库文件在/usr/local/lib/目录下。这里把安装目录指定为-–prefix=/usr则boost会直接安装到系统头文件目录和库文件目录下,可以省略配置环境变量。

  8. 然后root或者sudo执行 ldconfig

  9. 测试boost的使用

    
    #include <boost/shared_ptr.hpp>
    
    void test_shared_ptr()
    {
       boost::shared_ptr<int> shp1(new int(10));
       boost::shared_ptr<int> shp2(shp1);
       cout << *shp1 << endl;
       *shp1 = 100;
       cout << *shp2 << endl;
    }
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值