Skip to content

GNU Compiler Collection (GCC) on MeluXina

The MeluXina system environment provides the GCC compiler.

EasyBuild module description

 The GNU Compiler Collection includes front ends for C, C++, Objective-C, Fortran, Java, and Ada, as well as libraries for these languages (libstdc++, libgcj,...).

You can use GCC to compile your C/C++ programs.

GCC usage

Interactive

Reserve an interactive session:

salloc -A COMPUTE_ACCOUNT -t 01:00:00 -q dev --res cpudev -p cpu -N 1

The example above will allocate one CPU node in interactive mode (dev QoS with cpudev reservation). Load the GCC (Will load default version if not specified) module as in below script.

module load GCC
gcc hello.c -o ./HelloTest_C

Batch

GCC can also be used in a batch job using Slurm. The script below compile a simple C HelloWorld test on one CPU node allocated for 5 minutes.

#!/bin/bash -l
#SBATCH -N 1
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=1
#SBATCH -p cpu
#SBATCH -q test
#SBATCH --time 00:05:00

#Load GCC module
module load GCC

#Check GCC version
gcc --version

#Compile C program with GCC
gcc hello.c -o ./hello_c

#Execute the program
hello_c

It is recommended to use a Makefile to compile your program. Your Makefile should look like the example below:

#Defines compiler
CC=gcc

# These are the options we pass to the compiler.
# -std=c++14 means we want to use the C++14 standard. 
# -stdlib=libc++ specifies that we want to use the standard library implementation called libc++
# -c specifies making an object file, as you saw before
# -g specifies that we want to include "debugging symbols" which allows us to use a debugging program.
# -O0 specifies to do no optimizations on our code.
# -Wall, -Wextra, and -pedantic tells the compiler to look out for common problems with our code. -Werror makes it so that these warnings stop compilation.
CFLAGS = -std=c++14 -g -O0 -Wall -Wextra -Werror -pedantic

all: hello

hello: hello.o
        $CC $CFLAGS -o hello_c hello.o

hello.o: hello.cpp
          $CC $CFLAGS -c hello.c

It is also possible to compile via a Makefile inside a batch job:

#!/bin/bash -l
#SBATCH -N 1
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=128
#SBATCH -p cpu
#SBATCH -q test
#SBATCH --time 00:05:00

#Load GCC module
module load GCC

#Check GCC version
gcc --version

#Compile C program with GCC (in parallel)
make -j

#Execute the program
hello_c