• c++ boost库


    一、简介:

            Boost是为C++语言标准库提供扩展的一些C++程序库的总称。Boost库是一个可移植、提供源代码的C++库,作为标准库的后备,是C++标准化进程的开发引擎之一,是为C++语言标准库提供扩展的一些C++程序库的总称。

            Boost库由C++标准委员会库工作组成员发起,其中有些内容有望成为下一代C++标准库内容。在C++社区中影响甚大,是不折不扣的“准”标准库。

    管网:Boost C++ Libraries

    1. HP-EliteDesk-880-G2-TWR:~/boost_1_80_0$ tree -L 1
    2. .
    3. ├── boost #所有boost库头文件,90%以上的boost库源码都在这里
    4. ├── boost-build.jam
    5. ├── boostcpp.jam
    6. ├── boost.css
    7. ├── boost.png
    8. ├── bootstrap.bat
    9. ├── bootstrap.sh
    10. ├── doc #文档
    11. ├── index.htm
    12. ├── index.html
    13. ├── INSTALL
    14. ├── Jamroot
    15. ├── libs #所有组件的示例/测试/编译代码和说明文档
    16. ├── LICENSE_1_0.txt
    17. ├── more #库作者相关的文档
    18. ├── README.md
    19. ├── rst.css
    20. ├── status #可用于测试boost库的各个组件
    21. └── tools #b2、quickbook等一些自带的工具
    22. 6 directories, 13 files

    boost子目录是最为重要的目录。以头文件的形式分门别类存放了要使用的库代码: 

    1. ├─accumulators #累加器库
    2. ├─algorithm #算法库
    3. ├─archive #序列化库
    4. ├─asio #异步并发库
    5. ├─assign #赋值初始化库
    6. ├─atomic #原子操作库
    7. ├─bimap #双向关联数组
    8. ├─bind #bind表达式
    9. ├─chrono #时间处理库
    10. ├─circular_buffer #循环缓冲区容器
    11. ... #其他库
    12. ...
    13. └─xpressive #正则表达式库

    二、编译,安装

    2.1、linux平台

    1. HP-EliteDesk-880-G2-TWR:~/boost_1_80_0$ ./bootstrap.sh -h
    2. `./bootstrap.sh\' builds the Boost build system B2 and prepares Boost for
    3. building. This includes setting defaults in the project-config.jam which you
    4. can adjust prior to invoking B2.
    5. Usage: ./bootstrap.sh [OPTION]...
    6. Defaults for the options are specified in brackets.
    7. Configuration:
    8. -h, --help display this help and exit
    9. --with-bjam=BJAM use existing Boost.Jam executable (bjam)
    10. [automatically built]
    11. --with-toolset=TOOLSET use specific TOOLSET to build B2 and as default
    12. for building Boost
    13. [automatically detected]
    14. --show-libraries show the set of libraries that require build
    15. and installation steps (i.e., those libraries
    16. that can be used with --with-libraries or
    17. --without-libraries), then exit
    18. --with-libraries=list build only a particular set of libraries,
    19. describing using either a comma-separated list of
    20. library names or "all"
    21. [all]
    22. --without-libraries=list build all libraries except the ones listed []
    23. --with-icu enable Unicode/ICU support in Regex
    24. [automatically detected]
    25. --without-icu disable Unicode/ICU support in Regex
    26. --with-icu=DIR specify the root of the ICU library installation
    27. and enable Unicode/ICU support in Regex
    28. [automatically detected]
    29. --with-python=PYTHON specify the Python executable [python]
    30. --with-python-root=DIR specify the root of the Python installation
    31. [automatically detected]
    32. --with-python-version=X.Y specify the Python version as X.Y
    33. [automatically detected]
    34. Installation directories:
    35. --prefix=PREFIX install Boost into the given PREFIX
    36. [/usr/local]
    37. --exec-prefix=EPREFIX install Boost binaries into the given EPREFIX
    38. [PREFIX]
    39. More precise control over installation directories:
    40. --libdir=DIR install libraries here [EPREFIX/lib]
    41. --includedir=DIR install headers here [PREFIX/include]

    某些库不需要编译,包含头文件就可以使用,有些需要编译后才能使用。

    以下是必须编译成静态库或动态库才能使用的boost库:

    1. HP-EliteDesk-880-G2-TWR:~/boost_1_80_0$ ./bootstrap.sh --show-libraries
    2. Building B2 engine..
    3. ###
    4. ###
    5. ### Using 'gcc' toolset.
    6. ###
    7. ###
    8. g++ (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
    9. Copyright (C) 2019 Free Software Foundation, Inc.
    10. This is free software; see the source for copying conditions. There is NO
    11. warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    12. ###
    13. ###
    14. > 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
    15. tools/build/src/engine/b2
    16. The following Boost libraries have portions that require a separate build
    17. and installation step. Any library not listed here can be used by including
    18. the headers only.
    19. The Boost libraries requiring separate building and installation are:
    20. - atomic
    21. - chrono
    22. - container
    23. - context
    24. - contract
    25. - coroutine
    26. - date_time
    27. - exception
    28. - fiber
    29. - filesystem
    30. - graph
    31. - graph_parallel
    32. - headers
    33. - iostreams
    34. - json
    35. - locale
    36. - log
    37. - math
    38. - mpi
    39. - nowide
    40. - program_options
    41. - python
    42. - random
    43. - regex
    44. - serialization
    45. - stacktrace
    46. - system
    47. - test
    48. - thread
    49. - timer
    50. - type_erasure
    51. - wave

    三、使用

    先使用不需要编译的库,直接使用头文件,测试代码:

    1. #include //不需要单独编译的库
    2. #include
    3. using namespace std;
    4. int main()
    5. {
    6. using boost::lexical_cast;
    7. int a=lexical_cast<int>("123");
    8. double b=lexical_cast<double>("123.0123456789");
    9. string s0=lexical_cast(a);
    10. string s1=lexical_cast(b);
    11. cout<<"number: "<" "<
    12. cout<<"string: "<" "<
    13. int c=0;
    14. try{
    15. c=lexical_cast<int>("abcd");
    16. }
    17. catch(boost::bad_lexical_cast& e){
    18. cout<what()<
    19. }
    20. return 0;
    21. }

    四、裁剪

    假设我们允许程序员用A、B、C、D这样四个模块,那么可以这样:

    bcp --boost: A B C D 

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

  • 相关阅读:
    CYEZ 模拟赛 5
    js原型链污染详解
    常见内置函数
    视频用二维码怎么分享?扫码看视频在线制作方法
    4.Nginx优化,谁用谁说好
    【人民币识别】人民币序列号识别【含GUI Matlab源码 908期】
    【下一代对象专题】小文件管理全线升级,性能提升60%
    C++面试八股文:了解sizeof操作符吗?
    mysql基础_索引
    RK3568技术笔记 Ubuntu 安装VMware Tools
  • 原文地址:https://blog.csdn.net/wwwlyj123321/article/details/126637595