GNU Compiler Collection (gcc)
Guidance last updated: 20 October 2026
The GNU Compiler Collection (gcc) is a widely used, free collection of compilers for C (gcc), C++ (g++) and Fortran (gfortran).
It is possible to switch versions of the gcc compiler suite using modules.
Usage
After connecting to Stanage (see Establishing a SSH connection), start an interactive session:
salloc
Choose the compiler version by running one of the following lines:
module load GCC/15.2.0
module load GCC/14.3.0
module load GCC/14.2.0
module load GCC/13.3.0
module load GCC/13.2.0
module load GCC/12.3.0
module load GCC/12.2.0
module load GCC/11.3.0
module load GCC/15.2.0
module load GCC/14.3.0
module load GCC/14.2.0
module load GCC/13.2.0
module load GCC/12.3.0
module load GCC/12.2.0
For the examples below, load GCC/15.2.0. Confirm the compiler versions with:
gcc --version
g++ --version
gfortran --version
Use a matching toolchain when linking against module-provided libraries; see matching foss toolchains.
Compile and run a program
The following examples sum the integers from 1 to 100 and print 5050.
Choose one language and save its source file in your working directory.
Save as sum.c:
#include <stdio.h>
int main(void) {
int total = 0;
for (int i = 1; i <= 100; ++i) total += i;
printf("%d\n", total);
return 0;
}
Compile and run:
gcc -O2 -Wall -Wextra -std=c17 sum.c -o sum_c
./sum_c
Save as sum.cpp:
#include <iostream>
int main() {
int total = 0;
for (int i = 1; i <= 100; ++i) total += i;
std::cout << total << '\n';
return 0;
}
Compile and run:
g++ -O2 -Wall -Wextra -std=c++17 sum.cpp -o sum_cpp
./sum_cpp
Save as sum.f90:
program sum_numbers
implicit none
integer :: i, total
total = 0
do i = 1, 100
total = total + i
end do
print '(I0)', total
end program sum_numbers
Compile and run:
gfortran -O2 -Wall -Wextra sum.f90 -o sum_fortran
./sum_fortran
-O2 enables optimisation, -Wall -Wextra enables compiler warnings,
and -o names the executable. The C and C++ commands explicitly select
language standards.
Example batch submission
Save the C source above as sum.c and the following example batch submission
script as gcc.slurm in the same directory:
#!/bin/bash
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=1
#SBATCH --mem-per-cpu=1000
#SBATCH --time=00:05:00
# Stop if compilation fails so an old executable is not run.
set -e
export SLURM_EXPORT_ENV=ALL
module load GCC/15.2.0
gcc -O2 -Wall -Wextra -std=c17 sum.c -o sum_c
srun ./sum_c
Submit it from that directory with:
sbatch gcc.slurm
SIMD and vectorisation
Section guidance last updated: 1 December 2026
Single instruction, multiple data (SIMD) lets one CPU core perform the same operation on several values at once. GCC can do this automatically for loops such as multiplying each element of an array by a constant.
Check whether GCC vectorised a loop
Save this example as scale.c:
#include <stddef.h>
void scale(float *values, size_t count, float factor)
{
for (size_t i = 0; i < count; i++) {
values[i] *= factor;
}
}
With the GCC module loaded, compile the example and ask for vectorisation
diagnostics. The -c option stops after compiling the object file:
gcc -O3 -fopt-info-vec-optimized -fopt-info-vec-missed -c scale.c
Look for loop vectorized in the output. For your own code, missed
diagnostics can help explain why a loop was skipped. Time your workload to
see whether vectorisation improves performance and check that
the results still agree within the accuracy your workload requires.
If you set CPU-specific compiler options, target the nodes where the
program will run. For example, -march=native targets the build
machine, so the binary may use instructions unavailable on other nodes.
For operations such as matrix multiplication, consider an optimised library such as OpenBLAS.
Language support
Which version(s) of GCC support which features of the C99 and C11 standards?
Which version(s) of GCC support which features of the C++98, C++11, C++14 and C++17 standards?
Documentation
man pages are available on the system.
Once you have loaded the required version of gcc, type
man gcc
Installation notes
GCC was installed using Easybuild, build details can be found in $EBROOTGCC/easybuild with a given module loaded.