GNU Compiler Collection (GCC)

For detailed GCC documentation, refer to the GCC online documentation.

GCC is installed inside the container only. There is nothing to install outside the container or on your laptop.

Installation

GCC 14 is installed by default in the SUPS reference container images.

If you need to install GCC 14 manually in a custom development container image:

# DEV_SANDBOX must be on node-local storage, not NFS, Lustre, GPFS or PanFS
apptainer build --fakeroot --sandbox DEV_SANDBOX DEV_CONTAINER.sif
eval "$(sups-config --get SUPS_COMMON_DIR)" # set SUPS_COMMON_DIR
apptainer shell --writable --fakeroot --mount type=bind,src=${SUPS_COMMON_DIR},dst=/var/sups/common,ro DEV_SANDBOX

# In Rocky Linux 9.6 development container
dnf --assumeyes install \
    gcc-toolset-14-gcc \
    gcc-toolset-14-gcc-c++ \
    gcc-toolset-14-gcc-gfortran

# In SLES 15 SP7 development container
zypper --non-interactive install \
    gcc14 \
    gcc14-c++ \
    gcc14-fortran

Installing packages needs a persistent writable container: build a writable sandbox from the SIF as described in Writable sandboxes. Copy the rebuilt SIF to shared storage for multi-node runs.

Once you have completed all of the installation and configuration steps in this section, exit the sandbox shell and build a new SIF from it. Use that image for the verification and run commands below, which would otherwise open the original unmodified image. The rebuild must be the last customization step — anything done afterwards will not be in the SIF:

# Build to a new path; overwriting prompts, and fails when not on a terminal.
apptainer build --fakeroot CUSTOM_CONTAINER.sif DEV_SANDBOX

The commands below refer to DEV_CONTAINER.sif, which is what most readers use, since this component is installed in the SUPS reference images already. If you followed this optional installation, substitute CUSTOM_CONTAINER.sif for DEV_CONTAINER.sif in every command that follows.

GCC is available at the following paths:

Rocky Linux 9.6:

  • GCC C compiler: /opt/rh/gcc-toolset-14/root/usr/bin/gcc

  • GCC C++ compiler: /opt/rh/gcc-toolset-14/root/usr/bin/g++

  • GCC Fortran compiler: /opt/rh/gcc-toolset-14/root/usr/bin/gfortran

SLES 15 SP7:

  • GCC C compiler: /usr/bin/gcc-14

  • GCC C++ compiler: /usr/bin/g++-14

  • GCC Fortran compiler: /usr/bin/gfortran-14

Verify the Installation

Start an interactive shell from a container image and confirm the GCC compilers are available and can be invoked successfully:

# Launch an Apptainer container
apptainer shell DEV_CONTAINER.sif

# In Rocky Linux 9.6 development container
/opt/rh/gcc-toolset-14/root/usr/bin/gcc --version
/opt/rh/gcc-toolset-14/root/usr/bin/g++ --version
/opt/rh/gcc-toolset-14/root/usr/bin/gfortran --version

# In SLES 15 SP7 development container
/usr/bin/gcc-14 --version
/usr/bin/g++-14 --version
/usr/bin/gfortran-14 --version

[!important] The default GCC at /usr/bin/gcc is typically the system default version of GCC provided by the base OS which may not be version 14. To use GCC 14, you must invoke the compiler with the full path and the correct binary name as shown above.

Compile with GCC

To compile a C/C++/Fortran program, start a shell in a container, and invoke the GCC compilers with the full path:

# Launch an Apptainer container
apptainer shell DEV_CONTAINER.sif

# In Rocky Linux 9.6 development container
/opt/rh/gcc-toolset-14/root/usr/bin/gcc -fopenmp -o hello hello.c

# In SLES 15 SP7 development container
/usr/bin/gfortran-14 -o hello hello.f90

In Rocky Linux 9.6 containers, you can also source the GCC toolset enable script to add the GCC 14 compilers to your PATH:

source /opt/rh/gcc-toolset-14/enable
gcc -fopenmp -o hello hello.c

Differences from CPE

If you are transitioning from a Cray Programming Environment (CPE) system, here are some of the differences when using the GCC compilers.

There are no PrgEnv-gnu or craype modules in the SUPS container environment. Users who rely on the CrayPE compiler wrappers (cc, CC, and ftn) should now invoke the compilers directly by the full path, e.g., /opt/rh/gcc-toolset-14/root/usr/bin/gcc on Rocky Linux 9.6 or /usr/bin/gcc-14 on SLES 15 SP7.

The CrayPE compiler wrappers automatically add compiler and linker options to compile and link applications with certain libraries based on what modules are loaded. In the SUPS container environment, users now need to explicitly add the options to the command line. For example, to compile and link against Cray MPICH with the GCC compilers in a Rocky Linux 9.6 container, add the following options:

-I/opt/cray/pe/mpich/9.2.0/ofi/gnu/11.2/include -L/opt/cray/pe/mpich/9.2.0/ofi/gnu/11.2/lib -lmpi