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

标签 c++ docker gcc centos

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

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

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

谢谢 !

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

Using the types and functions in <filesystem> does not require linking with -lstdc++fs now.



来源: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

最佳答案

只需使用 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

关于c++ - 如何在 CentOS 8 docker 上安装 gcc/g++ 9 (centos :latest),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61590926/

相关文章:

docker - Docker 1.12群节点IP

C 中冲突的类型和变量命名

c++ - SFML - 创建光标和打印输入?

c++获取ip地址的代码

c++ - 在 C++ 中显示 vector 容器的内容

c++ - 将delphi记录 "polymorphic"转换为c/c++

c++ - 将 std::partition 与快速排序一起使用

docker - Docker的环境标准化

docker - 将docker日志获取到graylog2和本地

c - 在 linux 中静态链接库