前言
常用的 Linux 发行版一般不会自带最新的 GCC 等编译工具,如果我们想体验最新的 C++ 语法特性,就免不了要自己编译 GCC 或者下载预编译版本,这无疑使比较麻烦的。尤其时考虑到许多配套的编译和调试工具也需要升级,如 make、GDB 等,就更让人头大了。好在 RedHat 官方提供了 GCC Toolset 软件包,提供了便捷的安装使用体验,让你只需几条命令就可以用上最新的 GCC 版本。
安装 GCC Toolset
RedHat 从 RHEL 8 开始推出了 GCC Toolset,它是包括了最新开发工具和性能分析工具的一个软件集合,目前最新版本是 GCC Toolset 9,包括了以下工具:
名称 | 版本 | 简介 |
---|---|---|
GCC | 9.2.1 | A portable compiler suite with support for C, C++, and Fortran. |
GDB | 8.3 | A command-line debugger for programs written in C, C++, and Fortran. |
Valgrind | 3.15.0 | An instrumentation framework and a number of tools to profile applications in order to detect memory errors, identify memory management problems, and report any use of improper arguments in system calls. |
SystemTap | 4.1 | A tracing and probing tool to monitor the activities of the entire system without the need to instrument, recompile, install, and reboot. |
Dyninst | 10.1.0 | A library for instrumenting and working with user-space executables during their execution. |
binutils | 2.32 | A collection of binary tools and other utilities to inspect and manipulate object files and binaries. |
elfutils | 0.176 | A collection of binary tools and other utilities to inspect and manipulate ELF files. |
dwz | 0.12 | A tool to optimize DWARF debugging information contained in ELF shared libraries and ELF executables for size. |
make | 4.2.1 | A dependency-tracking build automation tool. |
strace | 5.1 | A debugging tool to monitor system calls that a program uses and signals it receives. |
ltrace | 0.7.91 | A debugging tool to display calls to dynamic libraries that a program makes. It can also monitor system calls executed by programs. |
annobin | 9.08 | A build security checking tool. |
GCC Toolset 在 RadHat 和 CentOS 都可以下载,使用下面的命令安装所有工具:
yum install gcc-toolset-9
你也可以只安装其中的某些工具,列出可用的软件包:
yum list available gcc-toolset-9-\*
然后安装其中的某些软件:
yum install package_name
使用 GCC Toolset
如果你想使用 GCC Toolset 中的某个工具,可以使用下面的命令:
scl enable gcc-toolset-9 ToolName
如果你想在一个 Shell 中全部使用 GCC Toolset 中的新版本而不是系统预装的旧版本,你可以使用下面的命令启动一个新的 Shell :
scl enable gcc-toolset-9 bash
在这个 Shell 下直接输入命令就可以执行新版本的编译工具,而不需要 scl
命令。
卸载 GCC Toolset
就像卸载普通软件包一样,执行下面的命令即可全部卸载:
yum remove gcc-toolset-N\*