【问题标题】:How to install gcc/g++ 9 on CentOS 8 docker (centos:latest)如何在 CentOS 8 docker 上安装 gcc/g++ 9 (centos:latest)
【发布时间】:2020-08-18 19:15:30
【问题描述】:

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

默认情况下centos:latest (aka 8) 将从常规发行版 repo 安装 gcc 8.3.1。

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

谢谢!

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

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

src:https://gcc.gnu.org/gcc-9/changes.html

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

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

【问题讨论】:

  • 你知道devtoolset-9吗?
  • 谢谢!我想我很久以前用过,但忘了它我会试一试!
  • @ThomasSablik 找不到在 Centos 8 上安装它的方法,这与具有 scl 和 devtoolset 软件包的 Centos 7 相反。
  • centos.pkgs.org/8/centos-appstream-x86_64/… 但不知道如何使用 AppStream
  • 你需要解决的根本问题是什么?

标签: c++ docker gcc centos


【解决方案1】:

只需使用dnf

dnf -y install gcc-toolset-9-gcc gcc-toolset-9-gcc-c++
source /opt/rh/gcc-toolset-9/enable

参考: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 dnf -y install gcc-toolset-9-gcc gcc-toolset-9-gcc-c++

RUN echo "source /opt/rh/gcc-toolset-9/enable" >> /etc/bashrc
SHELL ["/bin/bash", "--login", "-c"]
RUN gcc --version

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-16
    • 1970-01-01
    • 2020-08-18
    • 2020-07-03
    • 2023-03-20
    • 2021-06-23
    • 1970-01-01
    • 2023-03-22
    相关资源
    最近更新 更多