为了使用 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/