当前位置: 首页 > news >正文

c++ boost库

一、简介:

        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文件详解 - 莫水千流 - 博客园

相关文章:

  • pandas使用groupby函数基于指定分组变量对dataframe数据进行分组、使用first函数获取每个分组数据中每个分组的第一个样本数据
  • if选择结构分析
  • 【线性代数】MIT Linear Algebra Lecture 2: Elimination with matrices
  • 面试-测试软件Selenium
  • python--转换wrf输出的风场数据为网页可视化的json格式
  • 单细胞测序原理10X UMI Barcode
  • Rust-FFI复杂参数传递处理方式2--字符和字符串类型
  • A40I工控主板(SBC-X40I)CAN接口测试
  • Nginx - mac常用指令总结
  • 首先要学习什么:Docker 还是 Kubernetes?
  • springboot毕设项目兴趣学习平台02hz7(java+VUE+Mybatis+Maven+Mysql)
  • webpack5 - 之 开发环境的 服务器设置、sourcemap 配置、环境拆分( 清理上传打包缓存)
  • shell编程2-shell基础知识
  • 猿创征文 | 专做药品生产研发的程序员
  • 十三、【分布式微服务企业快速架构】SpringCloud分布式、微服务、云架构之Eclipse 创建 XML 文件
  • JavaScript 如何正确处理 Unicode 编码问题!
  • centos安装java运行环境jdk+tomcat
  • django开发-定时任务的使用
  • Docker容器管理
  • express如何解决request entity too large问题
  • IndexedDB
  • JavaScript的使用你知道几种?(上)
  • MQ框架的比较
  • MySQL常见的两种存储引擎:MyISAM与InnoDB的爱恨情仇
  • node-sass 安装卡在 node scripts/install.js 解决办法
  • OSS Web直传 (文件图片)
  • sessionStorage和localStorage
  • Spring Boot MyBatis配置多种数据库
  • win10下安装mysql5.7
  • 紧急通知:《观止-微软》请在经管柜购买!
  • 如何在招聘中考核.NET架构师
  • # Python csv、xlsx、json、二进制(MP3) 文件读写基本使用
  • (办公)springboot配置aop处理请求.
  • (七)c52学习之旅-中断
  • (七)理解angular中的module和injector,即依赖注入
  • (转)C#调用WebService 基础
  • (转)大型网站的系统架构
  • ***测试-HTTP方法
  • .Net Memory Profiler的使用举例
  • .NET是什么
  • .NET委托:一个关于C#的睡前故事
  • @vue/cli 3.x+引入jQuery
  • [ 环境搭建篇 ] 安装 java 环境并配置环境变量(附 JDK1.8 安装包)
  • []串口通信 零星笔记
  • [100天算法】-每个元音包含偶数次的最长子字符串(day 53)
  • [20171106]配置客户端连接注意.txt
  • [20180312]进程管理其中的SQL Server进程占用内存远远大于SQL server内部统计出来的内存...
  • [22]. 括号生成
  • [Android Pro] Notification的使用
  • [ffmpeg] 定制滤波器
  • [fsevents@^2.1.2] optional install error: Package require os(darwin) not compatible with your platfo
  • [linux] C语言Linux系统编程进程基本概念
  • [Notice] 朋友们,blog更新http://jiang-hongfei.spaces.live.com
  • [ROS2] --- ROS diff ROS2
  • [Selenium]通过Selenium实现在当前浏览器窗口点击一个图标之后,弹出另外一个窗口,关闭这个窗口,再回到原来的窗口进行操作...