一、简介:
????????Boost是为C++语言标准库提供扩展的一些C++程序库的总称。Boost库是一个可移植、提供源代码的C++库,作为标准库的后备,是C++标准化进程的开发引擎之一,是为C++语言标准库提供扩展的一些C++程序库的总称。
? ? ? ? Boost库由C++标准委员会库工作组成员发起,其中有些内容有望成为下一代C++标准库内容。在C++社区中影响甚大,是不折不扣的“准”标准库。
管网:Boost C++ Libraries
HP-EliteDesk-880-G2-TWR:~/boost_1_80_0$ tree -L 1
.
├── boost #所有boost库头文件,90%以上的boost库源码都在这里
├── boost-build.jam
├── boostcpp.jam
├── boost.css
├── boost.png
├── bootstrap.bat
├── bootstrap.sh
├── doc #文档
├── index.htm
├── index.html
├── INSTALL
├── Jamroot
├── libs #所有组件的示例/测试/编译代码和说明文档
├── LICENSE_1_0.txt
├── more #库作者相关的文档
├── README.md
├── rst.css
├── status #可用于测试boost库的各个组件
└── tools #b2、quickbook等一些自带的工具
6 directories, 13 files
boost子目录是最为重要的目录。以头文件的形式分门别类存放了要使用的库代码:?
├─accumulators #累加器库
├─algorithm #算法库
├─archive #序列化库
├─asio #异步并发库
├─assign #赋值初始化库
├─atomic #原子操作库
├─bimap #双向关联数组
├─bind #bind表达式
├─chrono #时间处理库
├─circular_buffer #循环缓冲区容器
... #其他库
...
└─xpressive #正则表达式库
二、编译,安装
2.1、linux平台
HP-EliteDesk-880-G2-TWR:~/boost_1_80_0$ ./bootstrap.sh -h
`./bootstrap.sh\' builds the Boost build system B2 and prepares Boost for
building. This includes setting defaults in the project-config.jam which you
can adjust prior to invoking B2.
Usage: ./bootstrap.sh [OPTION]...
Defaults for the options are specified in brackets.
Configuration:
-h, --help display this help and exit
--with-bjam=BJAM use existing Boost.Jam executable (bjam)
[automatically built]
--with-toolset=TOOLSET use specific TOOLSET to build B2 and as default
for building Boost
[automatically detected]
--show-libraries show the set of libraries that require build
and installation steps (i.e., those libraries
that can be used with --with-libraries or
--without-libraries), then exit
--with-libraries=list build only a particular set of libraries,
describing using either a comma-separated list of
library names or "all"
[all]
--without-libraries=list build all libraries except the ones listed []
--with-icu enable Unicode/ICU support in Regex
[automatically detected]
--without-icu disable Unicode/ICU support in Regex
--with-icu=DIR specify the root of the ICU library installation
and enable Unicode/ICU support in Regex
[automatically detected]
--with-python=PYTHON specify the Python executable [python]
--with-python-root=DIR specify the root of the Python installation
[automatically detected]
--with-python-version=X.Y specify the Python version as X.Y
[automatically detected]
Installation directories:
--prefix=PREFIX install Boost into the given PREFIX
[/usr/local]
--exec-prefix=EPREFIX install Boost binaries into the given EPREFIX
[PREFIX]
More precise control over installation directories:
--libdir=DIR install libraries here [EPREFIX/lib]
--includedir=DIR install headers here [PREFIX/include]
某些库不需要编译,包含头文件就可以使用,有些需要编译后才能使用。
以下是必须编译成静态库或动态库才能使用的boost库:
HP-EliteDesk-880-G2-TWR:~/boost_1_80_0$ ./bootstrap.sh --show-libraries
Building B2 engine..
###
###
### Using 'gcc' toolset.
###
###
g++ (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
###
###
> g++ -x c++ -std=c++11 -O2 -s -DNDEBUG builtins.cpp class.cpp command.cpp compile.cpp constants.cpp cwd.cpp debug.cpp debugger.cpp execcmd.cpp execnt.cpp execunix.cpp filesys.cpp filent.cpp fileunix.cpp frames.cpp function.cpp glob.cpp hash.cpp hcache.cpp hdrmacro.cpp headers.cpp jam_strings.cpp jam.cpp jamgram.cpp lists.cpp make.cpp make1.cpp md5.cpp mem.cpp modules.cpp native.cpp object.cpp option.cpp output.cpp parse.cpp pathnt.cpp pathsys.cpp pathunix.cpp regexp.cpp rules.cpp scan.cpp search.cpp startup.cpp subst.cpp sysinfo.cpp timestamp.cpp variable.cpp w32_getreg.cpp modules/order.cpp modules/path.cpp modules/property-set.cpp modules/regex.cpp modules/sequence.cpp modules/set.cpp -o b2
tools/build/src/engine/b2
The following Boost libraries have portions that require a separate build
and installation step. Any library not listed here can be used by including
the headers only.
The Boost libraries requiring separate building and installation are:
- atomic
- chrono
- container
- context
- contract
- coroutine
- date_time
- exception
- fiber
- filesystem
- graph
- graph_parallel
- headers
- iostreams
- json
- locale
- log
- math
- mpi
- nowide
- program_options
- python
- random
- regex
- serialization
- stacktrace
- system
- test
- thread
- timer
- type_erasure
- wave
三、使用
先使用不需要编译的库,直接使用头文件,测试代码:
#include <boost/lexical_cast.hpp> //不需要单独编译的库
#include <iostream>
using namespace std;
int main()
{
using boost::lexical_cast;
int a=lexical_cast<int>("123");
double b=lexical_cast<double>("123.0123456789");
string s0=lexical_cast<string>(a);
string s1=lexical_cast<string>(b);
cout<<"number: "<<a<<" "<<b<<endl;
cout<<"string: "<<s0<<" "<<s1<<endl;
int c=0;
try{
c=lexical_cast<int>("abcd");
}
catch(boost::bad_lexical_cast& e){
cout<<e.what()<<endl;
}
return 0;
}
四、裁剪
假设我们允许程序员用A、B、C、D这样四个模块,那么可以这样:
bcp --boost:<boost-root-directory>?A B C D?<output-directory>
这里A、B、C、D可以是:
Boost的头文件名。如: boost/shared_ptr.hpp
Boost的库名。如:regex
Boost的头文件标题:boost/shared_ptr 或者 shared_ptr
如果是在boost根目录下,那指定boost目录的参数也可以省去。
使用 bcp 裁剪 boost 库_丛继晔的博客-CSDN博客_boost 裁剪
boost裁剪和编译
ref:
嵌入式Linux开发的编程语言选择 - 知乎
Boost库的简介与安装_问我学院的博客-CSDN博客
嵌入式linux开发,boost移植,boost交叉编译_寞水的博客-CSDN博客_boost移植
boost库不安装使用和安装使用_fengyun_w的博客-CSDN博客
windows下编译和安装boost库 - rangers - 博客园
Boost Arm 交叉编译_FlyWine的博客-CSDN博客_arm boost
boost/config.hpp文件详解 - 莫水千流 - 博客园
|