skip to Main Content

In order to use the C++17 include <filesystem> I need gcc-9 package in my centos docker.

By default centos:latest (aka 8) will install gcc 8.3.1 from the regular distro repo.

Is there any PPA, testing repo, whatever, where I can easily install a gcc-9 (or later) package (i.e. not build it from source)

Thanks !

note: need gcc-9 to have good C++17 <filesystem> support.
GCC 9 Release note:

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

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

note2: CMake 3.16* doesn’t support any cxx_filesystem compiler feature AFAIK.
ref: https://cmake.org/cmake/help/latest/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html

note3: you can found log here: https://github.com/Mizux/KalistoUnpacker/runs/642516660?check_suite_focus=true

2

Answers


  1. Chosen as BEST ANSWER

    Simply use dnf

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

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

    Note: source won't work inside a Dockerfile so prefer to use:

    ENV PATH=/opt/rh/gcc-toolset-9/root/usr/bin:$PATH
    

    or better

    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
    

  2. this command work for me

    dnf install gcc --best --allowerasing
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search