如何在 CentOS 8 docker 上安装 gcc/g++ 9 (centos:latest)

Miz*_*zux 1 c++ gcc centos docker

为了使用 C++17 include,<filesystem>我需要在我的 centos docker 中使用gcc-9 包。

默认情况下,centos:latest(又名 8)将从常规发行版存储库安装 gcc 8.3.1。

是否有任何 PPA、测试 repo 等,我可以在其中轻松安装 gcc-9(或更高版本)包(即不是从源代码构建它)

谢谢 !

注意:需要 gcc-9 才能有良好的 C++17<filesystem>支持。
GCC 9 发行说明:

使用中的类型和函数<filesystem>不需要与-lstdc++fsnow链接。

源代码:https : //gcc.gnu.org/gcc-9/changes.html

注意 2:CMake 3.16* 不支持任何 cxx_filesystem 编译器功能 AFAIK。
参考:https : //cmake.org/cmake/help/latest/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html

注意3:你可以在这里找到日志:https : //github.com/Mizux/KalistoUnpacker/runs/642516660? check_suite_focus=true

Miz*_*zux 9

只需使用 dnf

dnf -y install gcc-toolset-9-gcc gcc-toolset-9-gcc-c++
source /opt/rh/gcc-toolset-9/enable
Run Code Online (Sandbox Code Playgroud)

参考:https : //centos.pkgs.org/8/centos-appstream-x86_64/gcc-toolset-9-gcc-9.1.1-2.4.el8.x86_64.rpm.html

注意:source不会在 Dockerfile 中工作,所以更喜欢使用:

ENV PATH=/opt/rh/gcc-toolset-9/root/usr/bin:$PATH
Run Code Online (Sandbox Code Playgroud)

或更好

RUN dnf -y install gcc-toolset-9-gcc gcc-toolset-9-gcc-c++

RUN echo "source /opt/rh/devtoolset-9/enable" >> /etc/bashrc
SHELL ["/bin/bash", "--login", "-c"]
RUN gcc --version
Run Code Online (Sandbox Code Playgroud)