【C++】环境搭建-编译安装Boost库
Boost库简介
Boost库是为C++语言标准库提供扩展的一些C++程序库的总称。
Boost库由Boost社区组织开发、维护。其目的是为C++程序员提供免费、同行审查的、可移植的程序库。Boost库可以与C++标准库共同工作,并且为其提供扩展功能。Boost库使用Boost License来授权使用,根据该协议,商业或非商业的使用都是允许并鼓励的。
Boost社区建立的初衷之一就是为C++的标准化工作提供可供参考的实现,Boost社区的发起人Dawes本人就是C++标准委员会的成员之一。在Boost库的开发中,Boost社区也在这个方向上取得了丰硕的成果。在送审的C++标准库TR1中,有十个Boost库成为标准库的候选方案。在更新的TR2中,有更多的Boost库被加入到其中。从某种意义上来讲,Boost库成为具有实践意义的准标准库。
大部分boost库功能的使用只需包括相应头文件即可,少数(如正则表达式库,文件系统库等)需要链接库。里面有许多具有工业强度的库,如graph库。
很多Boost中的库功能堪称对语言功能的扩展,其构造用尽精巧的手法,不要贸然的花费时间研读。Boost另外一面,比如Graph这样的库则是具有工业强度,结构良好,非常值得研读的精品代码,并且也可以放心的在产品代码中多多利用。
Boost库安装
通过YUM安装(版本较低 V1.53.0)
- 升级YUM到最新版本
sudo yum update
- 安装boost开发版
sudo yum install boost-devel
安装效果如下:
[root@localhost ~]# sudo yum update
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.ustc.edu.cn
* extras: mirrors.ustc.edu.cn
* updates: mirrors.ustc.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package NetworkManager.x86_64 1:1.18.8-1.el7 will be updated
---> Package NetworkManager.x86_64 1:1.18.8-2.el7_9 will be an update
---> Package NetworkManager-libnm.x86_64 1:1.18.8-1.el7 will be updated
---> Package NetworkManager-libnm.x86_64 1:1.18.8-2.el7_9 will be an update
---> Package NetworkManager-team.x86_64 1:1.18.8-1.el7 will be updated
---> Package NetworkManager-team.x86_64 1:1.18.8-2.el7_9 will be an update
---> Package NetworkManager-tui.x86_64 1:1.18.8-1.el7 will be updated
---> Package NetworkManager-tui.x86_64 1:1.18.8-2.el7_9 will be an update
---> Package bash.x86_64 0:4.2.46-34.el7 will be updated
---> Package bash.x86_64 0:4.2.46-35.el7_9 will be an update
---> Package bind-export-libs.x86_64 32:9.11.4-26.P2.el7 will be updated
---> Package bind-export-libs.x86_64 32:9.11.4-26.P2.el7_9.15 will be an update
---> Package binutils.x86_64 0:2.27-44.base.el7 will be updated
---> Package binutils.x86_64 0:2.27-44.base.el7_9.1 will be an update
---> Package ca-certificates.noarch 0:2020.2.41-70.0.el7_8 will be updated
---> Package ca-certificates.noarch 0:2023.2.60_v7.0.306-72.el7_9 will be an update
---> Package centos-release.x86_64 0:7-9.2009.0.el7.centos will be updated
---> Package centos-release.x86_64 0:7-9.2009.1.el7.centos will be an update
---> Package coreutils.x86_64 0:8.22-24.el7 will be updated
---> Package coreutils.x86_64 0:8.22-24.el7_9.2 will be an update
---> Package cronie.x86_64 0:1.4.11-23.el7 will be updated
---> Package cronie.x86_64 0:1.4.11-25.el7_9 will be an update
---> Package cronie-anacron.x86_64 0:1.4.11-23.el7 will be updated
---> Package cronie-anacron.x86_64 0:1.4.11-25.el7_9 will be an update
---> Package cyrus-sasl-lib.x86_64 0:2.1.26-23.el7 will be updated
---> Package cyrus-sasl-lib.x86_64 0:2.1.26-24.el7_9 will be an update
---> Package device-mapper.x86_64 7:1.02.170-6.el7 will be updated
---> Package device-mapper.x86_64 7:1.02.170-6.el7_9.5 will be an update
---> Package device-mapper-event.x86_64 7:1.02.170-6.el7 will be updated
---> Package device-mapper-event.x86_64 7:1.02.170-6.el7_9.5 will be an update
---> Package device-mapper-event-libs.x86_64 7:1.02.170-6.el7 will be updated
---> Package device-mapper-event-libs.x86_64 7:1.02.170-6.el7_9.5 will be an update
---> Package device-mapper-libs.x86_64 7:1.02.170-6.el7 will be updated
---> Package device-mapper-libs.x86_64 7:1.02.170-6.el7_9.5 will be an update
---> Package device-mapper-persistent-data.x86_64 0:0.8.5-3.el7 will be updated
---> Package device-mapper-persistent-data.x86_64 0:0.8.5-3.el7_9.2 will be an update
---> Package dhclient.x86_64 12:4.2.5-82.el7.centos will be updated
---> Package dhclient.x86_64 12:4.2.5-83.el7.centos.1 will be an update
---> Package dhcp-common.x86_64 12:4.2.5-82.el7.centos will be updated
---> Package dhcp-common.x86_64 12:4.2.5-83.el7.centos.1 will be an update
---> Package dhcp-libs.x86_64 12:4.2.5-82.el7.centos will be updated
---> Package dhcp-libs.x86_64 12:4.2.5-83.el7.centos.1 will be an update
---> Package diffutils.x86_64 0:3.3-5.el7 will be updated
---> Package diffutils.x86_64 0:3.3-6.el7_9 will be an update
---> Package dmidecode.x86_64 1:3.2-5.el7 will be updated
---> Package dmidecode.x86_64 1:3.2-5.el7_9.1 will be an update
---> Package firewalld.noarch 0:0.6.3-11.el7 will be updated
---> Package firewalld.noarch 0:0.6.3-13.el7_9 will be an update
---> Package firewalld-filesystem.noarch 0:0.6.3-11.el7 will be updated
---> Package firewalld-filesystem.noarch 0:0.6.3-13.el7_9 will be an update
---> Package freetype.x86_64 0:2.8-14.el7 will be updated
---> Package freetype.x86_64 0:2.8-14.el7_9.1 will be an update
---> Package glib2.x86_64 0:2.56.1-7.el7 will be updated
---> Package glib2.x86_64 0:2.56.1-9.el7_9 will be an update
---> Package grub2.x86_64 1:2.02-0.86.el7.centos will be updated
---> Package grub2.x86_64 1:2.02-0.87.0.2.el7.centos.14 will be an update
---> Package grub2-common.noarch 1:2.02-0.86.el7.centos will be updated
---> Package grub2-common.noarch 1:2.02-0.87.0.2.el7.centos.14 will be an update
---> Package grub2-pc.x86_64 1:2.02-0.86.el7.centos will be updated
---> Package grub2-pc.x86_64 1:2.02-0.87.0.2.el7.centos.14 will be an update
---> Package grub2-pc-modules.noarch 1:2.02-0.86.el7.centos will be updated
---> Package grub2-pc-modules.noarch 1:2.02-0.87.0.2.el7.centos.14 will be an
.....
pdated:
NetworkManager.x86_64 1:1.18.8-2.el7_9 NetworkManager-libnm.x86_64 1:1.18.8-2.el7_9 NetworkManager-team.x86_64 1:1.18.8-2.el7_9
NetworkManager-tui.x86_64 1:1.18.8-2.el7_9 bash.x86_64 0:4.2.46-35.el7_9 bind-export-libs.x86_64 32:9.11.4-26.P2.el7_9.15
binutils.x86_64 0:2.27-44.base.el7_9.1 ca-certificates.noarch 0:2023.2.60_v7.0.306-72.el7_9 centos-release.x86_64 0:7-9.2009.1.el7.centos
coreutils.x86_64 0:8.22-24.el7_9.2 cronie.x86_64 0:1.4.11-25.el7_9 cronie-anacron.x86_64 0:1.4.11-25.el7_9
cyrus-sasl-lib.x86_64 0:2.1.26-24.el7_9 device-mapper.x86_64 7:1.02.170-6.el7_9.5 device-mapper-event.x86_64 7:1.02.170-6.el7_9.5
device-mapper-event-libs.x86_64 7:1.02.170-6.el7_9.5 device-mapper-libs.x86_64 7:1.02.170-6.el7_9.5 device-mapper-persistent-data.x86_64 0:0.8.5-3.el7_9.2
dhclient.x86_64 12:4.2.5-83.el7.centos.1 dhcp-common.x86_64 12:4.2.5-83.el7.centos.1 dhcp-libs.x86_64 12:4.2.5-83.el7.centos.1
diffutils.x86_64 0:3.3-6.el7_9 dmidecode.x86_64 1:3.2-5.el7_9.1 firewalld.noarch 0:0.6.3-13.el7_9
firewalld-filesystem.noarch 0:0.6.3-13.el7_9 freetype.x86_64 0:2.8-14.el7_9.1 glib2.x86_64 0:2.56.1-9.el7_9
grub2.x86_64 1:2.02-0.87.0.2.el7.centos.14 grub2-common.noarch 1:2.02-0.87.0.2.el7.centos.14 grub2-pc.x86_64 1:2.02-0.87.0.2.el7.centos.14
grub2-pc-modules.noarch 1:2.02-0.87.0.2.el7.centos.14 grub2-tools.x86_64 1:2.02-0.87.0.2.el7.centos.14 grub2-tools-extra.x86_64 1:2.02-0.87.0.2.el7.centos.14
grub2-tools-minimal.x86_64 1:2.02-0.87.0.2.el7.centos.14 gzip.x86_64 0:1.5-11.el7_9 initscripts.x86_64 0:9.49.53-1.el7_9.1
iprutils.x86_64 0:2.4.17.1-3.el7_7 iwl100-firmware.noarch 0:39.31.5.1-82.el7_9 iwl1000-firmware.noarch 1:39.31.5.1-82.el7_9
iwl105-firmware.noarch 0:18.168.6.1-82.el7_9 iwl135-firmware.noarch 0:18.168.6.1-82.el7_9 iwl2000-firmware.noarch 0:18.168.6.1-82.el7_9
iwl2030-firmware.noarch 0:18.168.6.1-82.el7_9 iwl3160-firmware.noarch 0:25.30.13.0-82.el7_9 iwl3945-firmware.noarch 0:15.32.2.9-82.el7_9
iwl4965-firmware.noarch 0:228.61.2.24-82.el7_9 iwl5000-firmware.noarch 0:8.83.5.1_1-82.el7_9 iwl5150-firmware.noarch 0:8.24.2.2-82.el7_9
iwl6000-firmware.noarch 0:9.221.4.1-82.el7_9 iwl6000g2a-firmware.noarch 0:18.168.6.1-82.el7_9 iwl6000g2b-firmware.noarch 0:18.168.6.1-82.el7_9
iwl6050-firmware.noarch 0:41.28.5.1-82.el7_9 iwl7260-firmware.noarch 0:25.30.13.0-82.el7_9 kbd.x86_64 0:1.15.5-16.el7_9
kbd-legacy.noarch 0:1.15.5-16.el7_9 kbd-misc.noarch 0:1.15.5-16.el7_9 kernel-tools.x86_64 0:3.10.0-1160.118.1.el7
kernel-tools-libs.x86_64 0:3.10.0-1160.118.1.el7 kexec-tools.x86_64 0:2.0.15-51.el7_9.3 kpartx.x86_64 0:0.4.9-136.el7_9
libblkid.x86_64 0:2.23.2-65.el7_9.1 libcroco.x86_64 0:0.6.12-6.el7_9 libmount.x86_64 0:2.23.2-65.el7_9.1
libsmartcols.x86_64 0:2.23.2-65.el7_9.1 libssh2.x86_64 0:1.8.0-4.el7_9.1 libuuid.x86_64 0:2.23.2-65.el7_9.1
libxml2.x86_64 0:2.9.1-6.el7_9.6 linux-firmware.noarch 0:20200421-82.git78c0348.el7_9 lvm2.x86_64 7:2.02.187-6.el7_9.5
lvm2-libs.x86_64 7:2.02.187-6.el7_9.5 microcode_ctl.x86_64 2:2.1-73.20.el7_9 nspr.x86_64 0:4.35.0-1.el7_9
nss.x86_64 0:3.90.0-2.el7_9 nss-pem.x86_64 0:1.0.3-7.el7_9.1 nss-softokn.x86_64 0:3.90.0-6.el7_9
nss-softokn-freebl.x86_64 0:3.90.0-6.el7_9 nss-sysinit.x86_64 0:3.90.0-2.el7_9 nss-tools.x86_64 0:3.90.0-2.el7_9
nss-util.x86_64 0:3.90.0-1.el7_9 openldap.x86_64 0:2.4.44-25.el7_9 openssh.x86_64 0:7.4p1-23.el7_9
openssh-clients.x86_64 0:7.4p1-23.el7_9 openssh-server.x86_64 0:7.4p1-23.el7_9 polkit.x86_64 0:0.112-26.el7_9.1
python.x86_64 0:2.7.5-94.el7_9 python-firewall.noarch 0:0.6.3-13.el7_9 python-libs.x86_64 0:2.7.5-94.el7_9
python-perf.x86_64 0:3.10.0-1160.118.1.el7 rpm.x86_64 0:4.11.3-48.el7_9 rpm-build-libs.x86_64 0:4.11.3-48.el7_9
rpm-libs.x86_64 0:4.11.3-48.el7_9 rpm-python.x86_64 0:4.11.3-48.el7_9 rsyslog.x86_64 0:8.24.0-57.el7_9.3
selinux-policy.noarch 0:3.13.1-268.el7_9.2 selinux-policy-targeted.noarch 0:3.13.1-268.el7_9.2 sudo.x86_64 0:1.8.23-10.el7_9.3
systemd.x86_64 0:219-78.el7_9.9 systemd-libs.x86_64 0:219-78.el7_9.9 systemd-sysv.x86_64 0:219-78.el7_9.9
tuned.noarch 0:2.11.0-12.el7_9 tzdata.noarch 0:2024a-1.el7 util-linux.x86_64 0:2.23.2-65.el7_9.1
vim-minimal.x86_64 2:7.4.629-8.el7_9 virt-what.x86_64 0:1.18-4.el7_9.1 wpa_supplicant.x86_64 1:2.6-12.el7_9.2
xz.x86_64 0:5.2.2-2.el7_9 xz-libs.x86_64 0:5.2.2-2.el7_9
Complete!
root@localhost ~]# sudo yum install boost-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.ustc.edu.cn
* extras: mirrors.ustc.edu.cn
* updates: mirrors.ustc.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package boost-devel.x86_64 0:1.53.0-28.el7 will be installed
--> Processing Dependency: boost(x86-64) = 1.53.0-28.el7 for package: boost-devel-1.53.0-28.el7.x86_64
--> Processing Dependency: libboost_wserialization.so.1.53.0()(64bit) for package: boost-devel-1.53.0-28.el7.x86_64
--> Processing Dependency: libboost_wserialization-mt.so.1.53.0()(64bit) for package: boost-devel-1.53.0-28.el7.x86_64
--> Processing Dependency: libboost_wave.so.1.53.0()(64bit) for package: boost-devel-1.53.0-28.el7.x86_64
--> Processing Dependency: libboost_wave-mt.so.1.53.0()(64bit) for package: boost-devel-1.53.0-28.el7.x86_64
--> Processing Dependency: libboost_unit_test_framework.so.1.53.0()(64bit) for package: boost-devel-1.53.0-28.el7.x86_64
--> Processing Dependency: libboost_unit_test_framework-mt.so.1.53.0()(64bit) for package: boost-devel-1.53.0-28.el7.x86_64
--> Processing Dependency: libboost_timer.so.1.53.0()(64bit) for package: boost-devel-1.53.0-28.el7.x86_64
--> Processing Dependency: libboost_timer-mt.so.1.53.0()(64bit) for package: boost-devel-1.53.0-28.el7.x86_64
--> Processing Dependency: libboost_system.so.1.53.0()(64bit) for package: boost-devel-1.53.0-28.el7.x86_64
--> Processing Dependency: libboost_system-mt.so.1.53.0()(64bit) for package: boost-devel-1.53.0-28.el7.x86_64
--> Processing Dependency: libboost_signals.so.1.53.0()(64bit) for package: boost-devel-1.53.0-28.el7.x86_64
--> Processing Dependency: libboost_signals-mt.so.1.53.0()(64bit) for package: boost-devel-1.53.0-28.el7.x86_64
--> Processing Dependency: libboost_serialization.so.1.53.0()(64bit) for package: boost-devel-1.53.0-28.el7.x86_64
--> Processing Dependency: libboost_serialization-mt.so.1.53.0()(64bit) for package: boost-devel-1.53.0-28.el7.x86_64
--> Processing Dependency: libboost_regex.so.1.53.0()(64bit) for package: boost-devel-1.53.0-28.el7.x86_64
--> Processing Dependency: libboost_regex-mt.so.1.53.0()(64bit) for package: boost-devel-1.53.0-28.el7.x86_64
--> Processing Dependency: libboost_random.so.1.53.0()(64bit) for package: boost-devel-1.53.0-28.el7.x86_64
--> Processing Dependency: libboost_random-mt.so.1.53.0()(64bit) for package: boost-devel-1.53.0-28.el7.x86_64
--> Processing Dependency: libboost_python.so.1.53.0()(64bit) for package: boost-devel-1.53.0-28.el7.x86_64
--> Processing Dependency: libboost_python-mt.so.1.53.0()(64bit) for package: boost-devel-1.53.0-28.el7.x86_64
--> Processing Dependency: libboost_program_options.so.1.53.0()(64bit) for package: boost-devel-1.53.0-28.el7.x86_64
--> Processing Dependency: libboost_program_options-mt.so.1.53.0()(64bit) for package: boost-devel-1.53.0-28.el7.x86_64
--> Processing Dependency: libboost_prg_exec_monitor.so.1.53.0()(64bit) for package: boost-devel-1.53.0-28.el7.x86_64
--> Processing Dependency: libboost_prg_exec_monitor-mt.so.1.53.0()(64bit) for package: boost-devel-1.53.0-28.el7.x86_64
--> Processing Dependency: libboost_math_tr1l.so.1.53.0()(64bit) for package: boost-devel-1.53.0-28.el7.x86_64
--> Processing Dependency: libboost_math_tr1l-mt.so.1.53.0()(64bit) for package: boost-devel-1.53.0-28.el7.x86_64
--> Processing Dependency: libboost_math_tr1f.so.1.53.0()(64bit) for package: boost-devel-1.53.0-28.el7.x86_64
Verifying : boost-test-1.53.0-28.el7.x86_64 19/23
Verifying : boost-math-1.53.0-28.el7.x86_64 20/23
Verifying : boost-chrono-1.53.0-28.el7.x86_64 21/23
Verifying : boost-1.53.0-28.el7.x86_64 22/23
Verifying : boost-filesystem-1.53.0-28.el7.x86_64 23/23
Installed:
boost-devel.x86_64 0:1.53.0-28.el7
Dependency Installed:
boost.x86_64 0:1.53.0-28.el7 boost-atomic.x86_64 0:1.53.0-28.el7 boost-chrono.x86_64 0:1.53.0-28.el7 boost-context.x86_64 0:1.53.0-28.el7
boost-date-time.x86_64 0:1.53.0-28.el7 boost-filesystem.x86_64 0:1.53.0-28.el7 boost-graph.x86_64 0:1.53.0-28.el7 boost-iostreams.x86_64 0:1.53.0-28.el7
boost-locale.x86_64 0:1.53.0-28.el7 boost-math.x86_64 0:1.53.0-28.el7 boost-program-options.x86_64 0:1.53.0-28.el7 boost-python.x86_64 0:1.53.0-28.el7
boost-random.x86_64 0:1.53.0-28.el7 boost-regex.x86_64 0:1.53.0-28.el7 boost-serialization.x86_64 0:1.53.0-28.el7 boost-signals.x86_64 0:1.53.0-28.el7
boost-system.x86_64 0:1.53.0-28.el7 boost-test.x86_64 0:1.53.0-28.el7 boost-thread.x86_64 0:1.53.0-28.el7 boost-timer.x86_64 0:1.53.0-28.el7
boost-wave.x86_64 0:1.53.0-28.el7 libicu.x86_64 0:50.2-4.el7_7
Complete!
[root@localhost ~]#
.....
通过YUM安装的Boost版本为1.53,目前官网的版本为1.85,接下来我们通过编译安装Boost1.85
卸载命令
yum remove boost-devel
效果如下:
[root@localhost ~]# yum remove boost-devel
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package boost-devel.x86_64 0:1.53.0-28.el7 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
==========================================================================================================================================================================
Package Arch Version Repository Size
==========================================================================================================================================================================
Removing:
boost-devel x86_64 1.53.0-28.el7 @base 85 M
Transaction Summary
==========================================================================================================================================================================
Remove 1 Package
Installed size: 85 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : boost-devel-1.53.0-28.el7.x86_64 1/1
Verifying : boost-devel-1.53.0-28.el7.x86_64 1/1
Removed:
boost-devel.x86_64 0:1.53.0-28.el7
Complete!
[root@localhost ~]#
通过编译安装(官网最新版本1.85.0)
1.安装相关依赖
yum -y install gcc gcc-c++ python python-devel libicu libicu-devel zlib zlib-devel bzip2 bzip2-devel
效果如下:
[root@localhost ~]# yum -y install gcc gcc-c++ python python-devel libicu libicu-devel zlib zlib-devel bzip2 bzip2-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.ustc.edu.cn
* extras: mirrors.ustc.edu.cn
* updates: mirrors.ustc.edu.cn
Package gcc-4.8.5-44.el7.x86_64 already installed and latest version
Package gcc-c++-4.8.5-44.el7.x86_64 already installed and latest version
Package python-2.7.5-94.el7_9.x86_64 already installed and latest version
Package libicu-50.2-4.el7_7.x86_64 already installed and latest version
Package zlib-1.2.7-21.el7_9.x86_64 already installed and latest version
Package zlib-devel-1.2.7-21.el7_9.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package bzip2.x86_64 0:1.0.6-13.el7 will be installed
---> Package bzip2-devel.x86_64 0:1.0.6-13.el7 will be installed
---> Package libicu-devel.x86_64 0:50.2-4.el7_7 will be installed
---> Package python-devel.x86_64 0:2.7.5-94.el7_9 will be installed
--> Processing Dependency: python2-rpm-macros > 3-30 for package: python-devel-2.7.5-94.el7_9.x86_64
--> Processing Dependency: python-rpm-macros > 3-30 for package: python-devel-2.7.5-94.el7_9.x86_64
--> Running transaction check
---> Package python-rpm-macros.noarch 0:3-34.el7 will be installed
--> Processing Dependency: python-srpm-macros for package: python-rpm-macros-3-34.el7.noarch
---> Package python2-rpm-macros.noarch 0:3-34.el7 will be installed
--> Running transaction check
---> Package python-srpm-macros.noarch 0:3-34.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==========================================================================================================================================================================
Package Arch Version Repository Size
==========================================================================================================================================================================
Installing:
bzip2 x86_64 1.0.6-13.el7 base 52 k
bzip2-devel x86_64 1.0.6-13.el7 base 218 k
libicu-devel x86_64 50.2-4.el7_7 base 703 k
python-devel x86_64 2.7.5-94.el7_9 updates 399 k
Installing for dependencies:
python-rpm-macros noarch 3-34.el7 base 9.1 k
python-srpm-macros noarch 3-34.el7 base 8.8 k
python2-rpm-macros noarch 3-34.el7 base 8.1 k
Transaction Summary
==========================================================================================================================================================================
Install 4 Packages (+3 Dependent packages)
Total download size: 1.4 M
Installed size: 5.4 M
Downloading packages:
(1/7): bzip2-1.0.6-13.el7.x86_64.rpm | 52 kB 00:00:00
(2/7): python-srpm-macros-3-34.el7.noarch.rpm | 8.8 kB 00:00:00
(3/7): python-rpm-macros-3-34.el7.noarch.rpm | 9.1 kB 00:00:00
(4/7): python2-rpm-macros-3-34.el7.noarch.rpm | 8.1 kB 00:00:00
(5/7): bzip2-devel-1.0.6-13.el7.x86_64.rpm | 218 kB 00:00:00
(6/7): python-devel-2.7.5-94.el7_9.x86_64.rpm | 399 kB 00:00:00
(7/7): libicu-devel-50.2-4.el7_7.x86_64.rpm | 703 kB 00:00:01
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 999 kB/s | 1.4 MB 00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : python-srpm-macros-3-34.el7.noarch 1/7
Installing : python-rpm-macros-3-34.el7.noarch 2/7
Installing : python2-rpm-macros-3-34.el7.noarch 3/7
Installing : python-devel-2.7.5-94.el7_9.x86_64 4/7
Installing : libicu-devel-50.2-4.el7_7.x86_64 5/7
Installing : bzip2-1.0.6-13.el7.x86_64 6/7
Installing : bzip2-devel-1.0.6-13.el7.x86_64 7/7
Verifying : bzip2-devel-1.0.6-13.el7.x86_64 1/7
Verifying : python2-rpm-macros-3-34.el7.noarch 2/7
Verifying : bzip2-1.0.6-13.el7.x86_64 3/7
Verifying : python-rpm-macros-3-34.el7.noarch 4/7
Verifying : libicu-devel-50.2-4.el7_7.x86_64 5/7
Verifying : python-srpm-macros-3-34.el7.noarch 6/7
Verifying : python-devel-2.7.5-94.el7_9.x86_64 7/7
Installed:
bzip2.x86_64 0:1.0.6-13.el7 bzip2-devel.x86_64 0:1.0.6-13.el7 libicu-devel.x86_64 0:50.2-4.el7_7 python-devel.x86_64 0:2.7.5-94.el7_9
Dependency Installed:
python-rpm-macros.noarch 0:3-34.el7 python-srpm-macros.noarch 0:3-34.el7 python2-rpm-macros.noarch 0:3-34.el7
Complete!
[root@localhost ~]#
2.查询官网下载最新安装包并解压
boost官网地址:https://www.boost.org/
执行命令如下
cd /usr/local
wget https://boostorg.jfrog.io/artifactory/main/release/1.85.0/source/boost_1_85_0.tar.gz
tar -xzvf boost_1_85_0.tar.gz
cd boost_1_85_0
3.编译Boost
./bootstrap.sh
./b2
效果如下:
[root@localhost boost_1_85_0]# ./bootstrap.sh
Building B2 engine..
###
###
### Using 'gcc' toolset.
###
###
g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
Copyright (C) 2015 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 -pthread -O2 -s -DNDEBUG bindjam.cpp builtins.cpp class.cpp command.cpp compile.cpp constants.cpp cwd.cpp debug.cpp debugger.cpp execcmd.cpp execnt.cpp execunix.cpp filent.cpp filesys.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 option.cpp output.cpp parse.cpp pathnt.cpp pathsys.cpp pathunix.cpp regexp.cpp rules.cpp scan.cpp search.cpp startup.cpp tasks.cpp timestamp.cpp value.cpp variable.cpp w32_getreg.cpp mod_jam_builtin.cpp mod_jam_class.cpp mod_jam_errors.cpp mod_jam_modules.cpp mod_order.cpp mod_path.cpp mod_property_set.cpp mod_regex.cpp mod_sequence.cpp mod_set.cpp mod_string.cpp mod_summary.cpp mod_sysinfo.cpp mod_version.cpp -o b2
tools/build/src/engine/b2
Detecting Python version... 2.7
Detecting Python root... /usr
Unicode/ICU support for Boost.Regex?... /usr
Generating B2 configuration in project-config.jam for gcc...
Bootstrapping is done. To build, run:
./b2
To generate header files, run:
./b2 headers
The configuration generated uses gcc to build by default. If that is
unintended either use the --with-toolset option or adjust configuration, by
editing 'project-config.jam'.
Further information:
- Command line help:
./b2 --help
- Getting started guide:
http://www.boost.org/more/getting_started/unix-variants.html
- B2 documentation:
http://www.boost.org/build/
[root@localhost boost_1_85_0]# ./b2
Performing configuration checks
- default address-model : 64-bit [1]
- default architecture : x86 [1]
Building the Boost C++ Libraries.
- compiler supports SSE2 : yes [2]
- compiler supports SSE4.1 : yes [2]
- cxx11_static_assert : no [2]
- compiler supports SSE2 : yes [3]
- compiler supports SSE4.1 : yes [3]
- cxx11_static_assert : no [3]
- cxx11_variadic_templates : no [2]
- cxx11_variadic_templates : no [3]
- cxx11_hdr_ratio : no [2]
- cxx11_hdr_ratio : no [3]
- cxx20_hdr_concepts : no [2]
- cxx20_hdr_concepts : no [3]
- has std::atomic_ref : no [2]
- has -Wl,--no-undefined : yes [2]
- has statx : no [2]
- has statx syscall : no [2]
- cxx11_rvalue_references : no [2]
- has std::atomic_ref : no [3]
- has -Wl,--no-undefined : yes [3]
- has statx : no [3]
- has statx syscall : no [3]
- cxx11_rvalue_references : no [3]
- cxx11_auto_declarations : no [2]
- cxx11_auto_declarations : no [3]
- has init_priority attribute : yes [2]
- has stat::st_blksize : yes [2]
- has stat::st_mtim : yes [2]
- has stat::st_mtimensec : no [2]
- has stat::st_mtimespec : no [2]
- has stat::st_birthtim : no [2]
- has stat::st_birthtimensec : no [2]
- has stat::st_birthtimespec : no [2]
- has fdopendir(O_NOFOLLOW) : yes [2]
- has dirent::d_type : yes [2]
- has POSIX *at APIs : yes [2]
- has fallocate : yes [2]
- has_icu builds : yes [2]
warning: Graph library does not contain MPI-based parallel components.
note: to enable them, add "using mpi ;" to your user-config.jam.
note: to suppress this message, pass "--without-graph_parallel" to bjam.
- zlib : yes
- bzip2 : yes
- lzma : no
- zstd : no
- has_lzma_cputhreads builds : no [2]
- cxx11_constexpr : no [2]
- cxx11_constexpr : no [3]
- icu : yes [2]
- iconv (libc) : yes [2]
- icu : yes [3]
- iconv (libc) : yes [3]
- native atomic int32 supported : no [2]
- native syslog supported : yes [2]
- pthread supports robust mutexes : yes [2]
- Boost.Regex is header-only : no [2]
- lockfree boost::atomic_flag : no [2]
- compiler supports SSSE3 : yes [2]
- compiler supports AVX2 : yes [2]
- compiler supports SSSE3 : yes [3]
- compiler supports AVX2 : yes [3]
- native atomic int32 supported : no [3]
- native syslog supported : yes [3]
- pthread supports robust mutexes : yes [3]
- cxx11_lambdas : no [2]
- cxx11_lambdas : no [3]
- gcc visibility : yes [2]
- cxx11_noexcept : no [2]
- gcc visibility : yes [3]
- cxx11_noexcept : no [3]
warning: skipping optional Message Passing Interface (MPI) library.
note: to enable MPI support, add "using mpi ;" to user-config.jam.
note: to suppress this message, pass "--without-mpi" to bjam.
note: otherwise, you can safely ignore this message.
- std_wstreambuf builds : yes [2]
- std_wstreambuf : yes [2]
- BOOST_COMP_GNUC >= 4.3.0 : no [2]
- BOOST_COMP_GNUC >= 4.3.0 : no [4]
- compiler supports SSE2 : yes [4]
- compiler supports SSE4.1 : yes [4]
- cxx11_static_assert : no [4]
- compiler supports SSE2 : yes [5]
- compiler supports SSE4.1 : yes [5]
- cxx11_static_assert : no [5]
- cxx11_variadic_templates : no [4]
- cxx11_variadic_templates : no [5]
- cxx11_hdr_ratio : no [4]
- cxx11_hdr_ratio : no [5]
- cxx20_hdr_concepts : no [4]
- cxx20_hdr_concepts : no [5]
- has std::atomic_ref : no [4]
- has statx : no [4]
- has statx syscall : no [4]
- cxx11_rvalue_references : no [4]
- has std::atomic_ref : no [5]
- has statx : no [5]
- has statx syscall : no [5]
- cxx11_rvalue_references : no [5]
- cxx11_auto_declarations : no [4]
- cxx11_auto_declarations : no [5]
- has init_priority attribute : yes [4]
- has stat::st_blksize : yes [4]
- has stat::st_mtim : yes [4]
- has stat::st_mtimensec : no [4]
- has stat::st_mtimespec : no [4]
- has stat::st_birthtim : no [4]
- has stat::st_birthtimensec : no [4]
- has stat::st_birthtimespec : no [4]
- has fdopendir(O_NOFOLLOW) : yes [4]
- has dirent::d_type : yes [4]
- has POSIX *at APIs : yes [4]
- has fallocate : yes [4]
- has_icu builds : yes [4]
....
gcc.compile.c++ bin.v2/libs/test/build/gcc-4.8/release/link-static/threading-multi/visibility-hidden/xml_report_formatter.o
gcc.compile.c++ bin.v2/libs/test/build/gcc-4.8/release/threading-multi/visibility-hidden/compiler_log_formatter.o
gcc.compile.c++ bin.v2/libs/test/build/gcc-4.8/release/threading-multi/visibility-hidden/cpp_main.o
gcc.compile.c++ bin.v2/libs/test/build/gcc-4.8/release/threading-multi/visibility-hidden/debug.o
gcc.compile.c++ bin.v2/libs/test/build/gcc-4.8/release/threading-multi/visibility-hidden/decorator.o
gcc.compile.c++ bin.v2/libs/test/build/gcc-4.8/release/threading-multi/visibility-hidden/execution_monitor.o
gcc.compile.c++ bin.v2/libs/test/build/gcc-4.8/release/threading-multi/visibility-hidden/framework.o
gcc.compile.c++ bin.v2/libs/test/build/gcc-4.8/release/threading-multi/visibility-hidden/junit_log_formatter.o
gcc.compile.c++ bin.v2/libs/test/build/gcc-4.8/release/threading-multi/visibility-hidden/plain_report_formatter.o
gcc.compile.c++ bin.v2/libs/test/build/gcc-4.8/release/threading-multi/visibility-hidden/progress_monitor.o
gcc.compile.c++ bin.v2/libs/test/build/gcc-4.8/release/threading-multi/visibility-hidden/results_collector.o
gcc.compile.c++ bin.v2/libs/test/build/gcc-4.8/release/threading-multi/visibility-hidden/results_reporter.o
gcc.compile.c++ bin.v2/libs/test/build/gcc-4.8/release/threading-multi/visibility-hidden/test_tools.o
gcc.compile.c++ bin.v2/libs/test/build/gcc-4.8/release/threading-multi/visibility-hidden/test_tree.o
gcc.compile.c++ bin.v2/libs/test/build/gcc-4.8/release/threading-multi/visibility-hidden/unit_test_log.o
gcc.compile.c++ bin.v2/libs/test/build/gcc-4.8/release/threading-multi/visibility-hidden/unit_test_main.o
gcc.compile.c++ bin.v2/libs/test/build/gcc-4.8/release/threading-multi/visibility-hidden/unit_test_monitor.o
gcc.compile.c++ bin.v2/libs/test/build/gcc-4.8/release/threading-multi/visibility-hidden/unit_test_parameters.o
gcc.compile.c++ bin.v2/libs/test/build/gcc-4.8/release/threading-multi/visibility-hidden/xml_log_formatter.o
gcc.compile.c++ bin.v2/libs/test/build/gcc-4.8/release/threading-multi/visibility-hidden/xml_report_formatter.o
[root@localhost boost_1_85_0]#
这将编译并安装Boost库到默认的系统路径,如/usr/local/include和/usr/local/lib。如果你需要特定的编译选项或者库的子集,你可以在运行./bootstrap.sh时添加参数,例如,只编译线程库和系统库:
./bootstrap.sh --with-libraries=system,thread
./b2
4.安装Boost库到系统路径
sudo ./b2 install
效果如下:
- default address-model : 64-bit (cached) [1]
- default architecture : x86 (cached) [1]
- compiler supports SSE2 : yes (cached) [2]
- compiler supports SSE4.1 : yes (cached) [2]
- cxx11_static_assert : no (cached) [2]
- compiler supports SSE2 : yes (cached) [3]
- compiler supports SSE4.1 : yes (cached) [3]
- cxx11_static_assert : no (cached) [3]
- cxx11_variadic_templates : no (cached) [2]
- cxx11_variadic_templates : no (cached) [3]
- cxx11_hdr_ratio : no (cached) [2]
- cxx11_hdr_ratio : no (cached) [3]
- cxx20_hdr_concepts : no (cached) [2]
- cxx20_hdr_concepts : no (cached) [3]
- has std::atomic_ref : no (cached) [2]
- has -Wl,--no-undefined : yes (cached) [2]
- has statx : no (cached) [2]
- has statx syscall : no (cached) [2]
- cxx11_rvalue_references : no (cached) [2]
- has std::atomic_ref : no (cached) [3]
- has -Wl,--no-undefined : yes (cached) [3]
- has statx : no (cached) [3]
- has statx syscall : no (cached) [3]
- cxx11_rvalue_references : no (cached) [3]
- cxx11_auto_declarations : no (cached) [2]
- cxx11_auto_declarations : no (cached) [3]
- has init_priority attribute : yes (cached) [2]
- has stat::st_blksize : yes (cached) [2]
- has stat::st_mtim : yes (cached) [2]
- has stat::st_mtimensec : no (cached) [2]
- has stat::st_mtimespec : no (cached) [2]
- has stat::st_birthtim : no (cached) [2]
- has stat::st_birthtimensec : no (cached) [2]
- has stat::st_birthtimespec : no (cached) [2]
- has fdopendir(O_NOFOLLOW) : yes (cached) [2]
- has dirent::d_type : yes (cached) [2]
- has POSIX *at APIs : yes (cached) [2]
- has fallocate : yes (cached) [2]
- has_icu builds : yes (cached) [2]
warning: Graph library does not contain MPI-based parallel components.
note: to enable them, add "using mpi ;" to your user-config.jam.
note: to suppress this message, pass "--without-graph_parallel" to bjam.
- zlib : yes (cached)
- bzip2 : yes (cached)
- lzma : no (cached)
- zstd : no (cached)
- has_lzma_cputhreads builds : no (cached) [2]
- cxx11_constexpr : no (cached) [2]
- cxx11_constexpr : no (cached) [3]
- icu : yes (cached) [2]
- iconv (libc) : yes (cached) [2]
- icu : yes (cached) [3]
- iconv (libc) : yes (cached) [3]
- native atomic int32 supported : no (cached) [2]
- native syslog supported : yes (cached) [2]
- pthread supports robust mutexes : yes (cached) [2]
- Boost.Regex is header-only : no (cached) [2]
- lockfree boost::atomic_flag : no (cached) [2]
- compiler supports SSSE3 : yes (cached) [2]
- compiler supports AVX2 : yes (cached) [2]
- compiler supports SSSE3 : yes (cached) [3]
- compiler supports AVX2 : yes (cached) [3]
- native atomic int32 supported : no (cached) [3]
- native syslog supported : yes (cached) [3]
- pthread supports robust mutexes : yes (cached) [3]
- cxx11_lambdas : no (cached) [2]
- cxx11_lambdas : no (cached) [3]
- gcc visibility : yes (cached) [2]
- cxx11_noexcept : no (cached) [2]
- gcc visibility : yes (cached) [3]
- cxx11_noexcept : no (cached) [3]
warning: skipping optional Message Passing Interface (MPI) library.
note: to enable MPI support, add "using mpi ;" to user-config.jam.
note: to suppress this message, pass "--without-mpi" to bjam.
note: otherwise, you can safely ignore this message.
- std_wstreambuf builds : yes (cached) [2]
....
gcc.compile.c++ bin.v2/libs/test/build/gcc-4.8/release/threading-multi/visibility-hidden/plain_report_formatter.o
gcc.compile.c++ bin.v2/libs/test/build/gcc-4.8/release/threading-multi/visibility-hidden/progress_monitor.o
gcc.compile.c++ bin.v2/libs/test/build/gcc-4.8/release/threading-multi/visibility-hidden/results_collector.o
gcc.compile.c++ bin.v2/libs/test/build/gcc-4.8/release/threading-multi/visibility-hidden/results_reporter.o
gcc.compile.c++ bin.v2/libs/test/build/gcc-4.8/release/threading-multi/visibility-hidden/test_tools.o
gcc.compile.c++ bin.v2/libs/test/build/gcc-4.8/release/threading-multi/visibility-hidden/test_tree.o
gcc.compile.c++ bin.v2/libs/test/build/gcc-4.8/release/threading-multi/visibility-hidden/unit_test_log.o
gcc.compile.c++ bin.v2/libs/test/build/gcc-4.8/release/threading-multi/visibility-hidden/unit_test_main.o
gcc.compile.c++ bin.v2/libs/test/build/gcc-4.8/release/threading-multi/visibility-hidden/unit_test_monitor.o
gcc.compile.c++ bin.v2/libs/test/build/gcc-4.8/release/threading-multi/visibility-hidden/unit_test_parameters.o
gcc.compile.c++ bin.v2/libs/test/build/gcc-4.8/release/threading-multi/visibility-hidden/xml_log_formatter.o
gcc.compile.c++ bin.v2/libs/test/build/gcc-4.8/release/threading-multi/visibility-hidden/xml_report_formatter.o
[root@localhost boost_1_85_0]#
Boost库验证
示例代码:
#include <boost/filesystem.hpp>
#include <iostream>
int main(int argc, char* argv[])
{
if (argc < 2){
std::cout << "Usage: " << argv[0] << " path\n";
return 1;
}
boost::filesystem::path p(argv[1]);
if (boost::filesystem::exists(p)) {
if (boost::filesystem::is_directory(p))
std::cout << p << " is a directory.\n";
else if (boost::filesystem::is_regular_file(p))
std::cout << p << " is a regular file.\n";
else
std::cout << p << " exists but is not a directory or regular file.\n";
} else {
std::cout << p << " does not exist.\n";
}
return 0;
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.28)
project(boost_example)
set(BOOST_ROOT "/usr/include")
set(Boost_INCLUDE_DIR "/usr/include")
set(Boost_SYSTEM_LIBRARY "/usr/include/boost/stage/lib")
set(CMAKE_CXX_STANDARD 20)
set(boostlib filesystem program_options regex)
#
find_package(Boost REQUIRED COMPONENTS ${boostlib})
add_executable(boost_example main.cpp)
if(Boost_FOUND)
message(STATUS "Boost version found")
message(STATUS " Boost libraries:${Boost_LIBRARIES}")
target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES})
else()
message(STATUS "Boost version not found")
endif()