C++ Boost库

发布时间 2023-11-26 11:47:25作者: Alpha205

《C++ Boost库》

1. Preface

  cxmsc

2. Boost库编译

  • 解压boost源码压缩目录
  • Windows平台下,打开cmd,运行脚本bootstrap.bat脚本
  • 生成b2.exe文件

boost需要通b2.exe来自动编译源码;在编译之前,需要指定一些列参数:

首先可通过--help命令来查看相关的参数

# 展示boost里所有的库
b2.exe --show-libraries

参数含义:

  • --prefix/--stagedir
    分别对应install和stage模式下的安装目录
  • install/stage
    stage表示只生成库(lib和dll),install会额外生成包含头文件的include目录。这个include目录实际就是从boost源码解压后的include目录拷贝过去的;
  • toolset 指定编译器
    可选项包含:(borland, gcc, msvc(VC6), msvc-10.0(vs2010), msvc-12.0(vs2013), msvc-14.0(vs2015))
  • with/without
    选择编译或者不编译哪些库,可以根据需要进行选择,默认为全部编译,可通过b2.exe --show-libraries来查看boost下所有的库
  • build_dir
    中间问价的生成路径,如果无特殊需求,可不设置,默认路径为boost源码根目录下的bin.v2目录下
  • link
    选择生成动态链接库/静态链接库,可选值 static / shared
  • runtime-link
    指定boost编译时是动态/静态链接c++运行时库,可选值static / shared
  • threading
    是否开启多线程编译, 可选值 single / multi
  • debug / releae
    指定编译的产物类型为debug或者release
# debug和release可同时编译
b2.exe install --prefix=D:\software\boost_1_82_0 toolset=gcc link=shared runtime-link=shared threading=multi --with-thread release debug