linux下编译boost

linux下编译boost

下载boot库

官方下载地址

在这里插入图片描述

下载完成会解压。

编译

1.进入解压后的文件夹内

```
cd boost_1_69_0 
```
  1. 执行下面的语句

    ./bootstrap.sh --with-libraries=all --with-toolset=gcc
    
  • –with-libraries 指定编译哪些boost库,all的话就是全部编译,只想编译部分库的话就把库的名称写上,之间用 , 号分隔即可,可指定的库下面介绍
  • –with-toolset 指定编译时使用哪种编译器,Linux下使用gcc即可,如果系统中安装了多个版本的gcc,在这里可以指定gcc的版本,比如–with-toolset=gcc-4.4

命令执行完后看到如下所示即为成功:

```Building Boost.Build engine with toolset gcc... tools/build/src/engine/bin.linuxx86_64/b2
Detecting Python version... 3.6
Detecting Python root... /opt/anaconda3
Unicode/ICU support for Boost.Regex?... /usr
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

```
  1. 再执行下面的命令

    ./b2 toolset=gcc
    

可指定的库有:

库名 说明

  • atomic
  • chrono
  • context
  • coroutine
  • date_time
  • exception
  • filesystem
  • graph 图组件和算法
  • graph_parallel
  • iostreams
  • locale
  • log
  • math
  • mpi 用模板实现的元编程框架
  • program_options
  • python 把C++类和函数映射到Python之中
  • random
  • regex 正则表达式库
  • serialization
  • signals
  • system
  • test
  • thread 可移植的C++多线程库
  • timer
  • wave
  1. 编译后的库文件位置

    boost_1_69_0/bin.v2/libs/
    

    都在此文件夹内。

    在这里插入图片描述

安装到系统

执行下面的命令就可以安装到系统环境下(本质就是copy)

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

如果想让库立即生效,需要执行下面的命令

ldconfig
发布了145 篇原创文章 · 获赞 357 · 访问量 44万+

猜你喜欢

转载自blog.csdn.net/wf19930209/article/details/88809428