• CentOS 7 编译安装Boost


    1、前提条件

    linux平台/CentOS 7 下要编译安装Boostgcc和gcc-c++之外,还需要两个开发库:bzip2-devel 和python-devel ,因此在安装前应该先保证这两个库已经安装。

    安装指令:

    yum install bzip2 bzip2-devel bzip2-libs python-devel

    CentOS 7安装效果:

    1. [root@localhost ~]# yum install bzip2 bzip2-devel bzip2-libs python-devel
    2. 已加载插件:fastestmirror
    3. Determining fastest mirrors
    4. * base: mirrors.ustc.edu.cn
    5. * extras: mirrors.ustc.edu.cn
    6. * updates: mirrors.163.com
    7. base | 3.6 kB 00:00:00
    8. docker-ce-stable | 3.5 kB 00:00:00
    9. extras | 2.9 kB 00:00:00
    10. updates | 2.9 kB 00:00:00
    11. (1/2): docker-ce-stable/7/x86_64/primary_db | 117 kB 00:00:26
    12. (2/2): updates/7/x86_64/primary_db | 23 MB 00:02:58
    13. 软件包 bzip2-libs-1.0.6-13.el7.x86_64 已安装并且是最新版本
    14. 正在解决依赖关系
    15. --> 正在检查事务
    16. *********

    2、安装

    Boost 官网下载地址:https://www.boost.org/

    将下载的boost 源码:boost_1_83_0_rc1.tar.gz, 上传CentOS 7 指定目录,我的目录地址为:/usr/local/source_code/.

    CentOS  7 指令效果:

    1. [root@localhost ~]# cd /usr/local/source_code/
    2. [root@localhost source_code]# ll
    3. 总用量 146560
    4. -rw-r--r--. 1 root root 144648962 1013 10:33 boost_1_83_0_rc1.tar.gz
    5. drwxr-xr-x. 2 root root 42 918 17:32 c_demo
    6. drwxrwxr-x. 6 root root 4096 1010 09:44 hiredis-1.2.0
    7. -rw-r--r--. 1 root root 126216 1010 09:42 hiredis-1.2.0.tar.gz
    8. drwxr-xr-x. 2 root root 50 1010 10:37 hiredis_demo
    9. drwxr-xr-x. 5 500 users 8192 94 15:28 jpeg-9e
    10. -rw-r--r--. 1 root root 1046935 94 15:23 jpegsrc.v9e.tar.gz
    11. -rw-r--r--. 1 root root 4234219 831 16:22 release-3.4.13.tar.gz
    12. drwxr-xr-x. 2 root root 52 1010 12:54 zookeeper_demo
    13. drwxrwxr-x. 8 root root 259 831 16:33 zookeeper-release-3.4.13

    解压Boost 源码 并安装,执行如下命令:

    1. # 解压boost 源码
    2. tar -zxvf boost_1_83_0_rc1.tar.gz
    3. # 进入boost 源码目录
    4. cd boost_1_83_0
    5. # 启动 boost 安装指南脚本
    6. ./bootstrap.sh
    7. # 安装boost 全部 模块
    8. ./b2 install --with=all

     CentOS  7 指令效果:

    1. # 进入Boost 源码目录
    2. [root@localhost source_code]# cd boost_1_83_0
    3. # 启动Boost 库安装指南sh
    4. [root@localhost boost_1_83_0]# ./bootstrap.sh
    5. Building B2 engine..
    6. ###
    7. ###
    8. ### Using 'gcc' toolset.
    9. ###
    10. ###
    11. g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
    12. Copyright © 2015 Free Software Foundation, Inc.
    13. 本程序是自由软件;请参看源代码的版权声明。本软件没有任何担保;
    14. 包括没有适销性和某一专用目的下的适用性担保。
    15. ###
    16. ###
    17. > 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
    18. tools/build/src/engine/b2
    19. Detecting Python version... 2.7
    20. Detecting Python root... /usr
    21. Unicode/ICU support for Boost.Regex?... /usr
    22. Generating B2 configuration in project-config.jam for gcc...
    23. Bootstrapping is done. To build, run:
    24. ./b2
    25. To generate header files, run:
    26. ./b2 headers
    27. ******
    28. # 安装Boost 模块
    29. [root@localhost boost_1_83_0]# ./b2 install --with=all
    30. Performing configuration checks
    31. - default address-model : 64-bit [1]
    32. - default architecture : x86 [1]
    33. - compiler supports SSE2 : yes [2]
    34. - compiler supports SSE4.1 : yes [2]
    35. - has std::atomic_ref : no [2]
    36. - has -Wl,--no-undefined : yes [2]
    37. - has statx : no [2]
    38. - has statx syscall : no [2]
    39. - has init_priority attribute : yes [2]
    40. - has stat::st_blksize : yes [2]
    41. - has stat::st_mtim : yes [2]
    42. - has stat::st_mtimensec : no [2]
    43. - has stat::st_mtimespec : no [2]
    44. - has stat::st_birthtim : no [2]
    45. - has stat::st_birthtimensec : no [2]
    46. - has stat::st_birthtimespec : no [2]
    47. - has fdopendir(O_NOFOLLOW) : yes [2]
    48. - has dirent::d_type : yes [2]
    49. - has POSIX *at APIs : yes [2]
    50. - cxx11_auto_declarations : no [2]
    51. - cxx11_auto_declarations : no [3]
    52. - has_icu builds : yes [2]
    53. warning: Graph library does not contain MPI-based parallel components.
    54. note: to enable them, add "using mpi ;" to your user-config.jam.
    55. note: to suppress this message, pass "--without-graph_parallel" to bjam.
    56. - zlib : yes
    57. - bzip2 : yes
    58. - lzma : no
    59. - zstd : no
    60. - has_lzma_cputhreads builds : no [2]
    61. - cxx11_constexpr : no [2]
    62. - cxx11_constexpr : no [3]
    63. - iconv (libc) : yes [2]
    64. - icu : yes [2]
    65. - iconv (libc) : yes [3]
    66. ******

    3、Boost 快速上手Demo

    在指定目录(/usr/local/source_code) ,创建boost 测试目录(boost_demo)。指令如下:

    1. [root@localhost source_code]# mkdir boost_demo
    2. [root@localhost source_code]# cd boost_demo/
    3. [root@localhost boost_demo]# ll
    4. 总用量 0

    在boost_demo 目录下,创建boost 测试程序:accumulators_demo.cpp。指令如下:

    1. [root@localhost boost_demo]# vi accumulators_demo.cpp

    编辑 accumulators_demo.cpp 文件内容如下:

    1. #include <iostream>
    2. #include <boost/accumulators/accumulators.hpp>
    3. #include <boost/accumulators/statistics/stats.hpp>
    4. #include <boost/accumulators/statistics/mean.hpp>
    5. #include <boost/accumulators/statistics/moment.hpp>
    6. using namespace boost::accumulators;
    7. int main()
    8. {
    9. // Define an accumulator set for calculating the mean and the
    10. // 2nd moment ...
    11. accumulator_set<double, stats<tag::mean, tag::moment<2> > > acc;
    12. // push in some data ...
    13. acc(1.2);
    14. acc(2.3);
    15. acc(3.4);
    16. acc(4.5);
    17. // Display the results ...
    18. std::cout << "Mean: " << mean(acc) << std::endl;
    19. std::cout << "Moment: " << moment<2>(acc) << std::endl;
    20. return 0;
    21. }

     编译accumulators_demo.cpp 文件并执行。

    1. [root@localhost boost_demo]# g++ accumulators_demo.cpp -o accumulators_demo
    2. In file included from /usr/local/include/boost/function/detail/prologue.hpp:12:0,
    3. from /usr/local/include/boost/function.hpp:30,
    4. from /usr/local/include/boost/parameter/aux_/tagged_argument.hpp:88,
    5. from /usr/local/include/boost/parameter/aux_/tag.hpp:11,
    6. from /usr/local/include/boost/parameter/keyword.hpp:10,
    7. from /usr/local/include/boost/parameter/nested_keyword.hpp:10,
    8. from /usr/local/include/boost/accumulators/accumulators_fwd.hpp:229,
    9. from /usr/local/include/boost/accumulators/framework/accumulator_set.hpp:29,
    10. from /usr/local/include/boost/accumulators/accumulators.hpp:12,
    11. from accumulators_demo.cpp:2:
    12. /usr/local/include/boost/function/detail/requires_cxx11.hpp:18:192: 附注:#pragma message:C++03 support was deprecated in Boost.Function 1.82 and will be removed in Boost.Function 1.84. Please open an issue in https://github.com/boostorg/function if you want it retained.
    13. BOOST_PRAGMA_MESSAGE("C++03 support was deprecated in Boost.Function 1.82 and will be removed in Boost.Function 1.84. Please open an issue in https://github.com/boostorg/function if you want it retained.")
    14. ^
    15. In file included from /usr/local/include/boost/bind/mem_fn.hpp:24:0,
    16. from /usr/local/include/boost/mem_fn.hpp:22,
    17. from /usr/local/include/boost/function/detail/prologue.hpp:19,
    18. from /usr/local/include/boost/function.hpp:30,
    19. from /usr/local/include/boost/parameter/aux_/tagged_argument.hpp:88,
    20. from /usr/local/include/boost/parameter/aux_/tag.hpp:11,
    21. from /usr/local/include/boost/parameter/keyword.hpp:10,
    22. from /usr/local/include/boost/parameter/nested_keyword.hpp:10,
    23. from /usr/local/include/boost/accumulators/accumulators_fwd.hpp:229,
    24. from /usr/local/include/boost/accumulators/framework/accumulator_set.hpp:29,
    25. from /usr/local/include/boost/accumulators/accumulators.hpp:12,
    26. from accumulators_demo.cpp:2:
    27. /usr/local/include/boost/bind/detail/requires_cxx11.hpp:18:180: 附注:#pragma message:C++03 support was deprecated in Boost.Bind 1.82 and will be removed in Boost.Bind 1.84. Please open an issue in https://github.com/boostorg/bind if you want it retained.
    28. BOOST_PRAGMA_MESSAGE("C++03 support was deprecated in Boost.Bind 1.82 and will be removed in Boost.Bind 1.84. Please open an issue in https://github.com/boostorg/bind if you want it retained.")
    29. ^
    30. In file included from /usr/local/include/boost/typeof/typeof.hpp:16:0,
    31. from /usr/local/include/boost/accumulators/numeric/functional.hpp:22,
    32. from /usr/local/include/boost/accumulators/statistics/mean.hpp:14,
    33. from accumulators_demo.cpp:4:
    34. /usr/local/include/boost/typeof/detail/requires_cxx11.hpp:14:102: 附注:#pragma message:C++03 support was deprecated in Boost.Typeof 1.82 and will be removed in Boost.Typeof 1.84.
    35. BOOST_PRAGMA_MESSAGE("C++03 support was deprecated in Boost.Typeof 1.82 and will be removed in Boost.Typeof 1.84.")
    36. ^
    37. [root@localhost boost_demo]# ll
    38. 总用量 244
    39. -rwxr-xr-x. 1 root root 245128 1013 10:57 accumulators_demo
    40. -rw-r--r--. 1 root root 678 1013 10:53 accumulators_demo.cpp
    41. [root@localhost boost_demo]# ./accumulators_demo
    42. Mean: 2.85
    43. Moment: 9.635

    4、Boost  常用库

    Boost 是一组扩展了 C++ 功能的库。常用的包括:

    1. Boost.Asio:包含了一套网络和底层 I/O 编程的接口,支持同步、异步操作。

    2. Boost.Unordered:提供了类似 C++11 中的 std::unordered_map, std::unordered_set 等的无序容器。

    3. Boost.Thread:封装了线程相关的接口,如线程类、互斥量、条件变量等。

    4. Boost.Python:扩展了 Python/C++ 的转换机制,以便于在 Python 和 C++之间进行进行更灵活的程序集成。

    5. Boost.Smart_Ptr:包含智能指针,如 shared_ptr,weak_ptr,scoped_ptr 等用于资源管理的类。

    6. Boost.Filesystem:提供一套跨平台的文件系统访问方法。

    7. Boost.Graph:提供一套图数据结构及相关算法。

    8. Boost.Regex:封装了正则表达式的类。

    9. Boost.Log:提供一套跨平台的日志库。

    10. Boost.Date_Time:时间和日期库,提供一种简单、易于操作的方式来处理时间和日期。

  • 相关阅读:
    macOS - 获取硬件设备信息
    这几个高效软件简直是打工人的宝藏软件
    c++万能开头<bits/stdc++.h>
    日志收集项目遇到的问题
    手撕 视觉slam14讲 ch13 代码(5)双目初始化 StereoInit()
    Unity ECS 内存分配器原理详解
    [深度学习][pytorch]pytorch实现一个简单得线性回归模型并训练
    云游戏发行是什么?云游戏发行的演进历程
    Linux 中 WIFI 和热点的使用
    java-php-python-基于Springboot的水世界乐园管理系统计算机毕业设计
  • 原文地址:https://blog.csdn.net/zhouzhiwengang/article/details/133806508