Skip to content

Clang compiler on MeluXina

The MeluXina system environment provides the Clang compiler.

EasyBuild module description

C, C++, Objective-C compiler, based on LLVM. Does not include C++ standard library -- use libstdc++ from GCC.

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

Clang 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 Clang (Will load default version if not specified) module as in below script.

module load Clang
clang hello.c -o ./HelloTest_C

Batch

Clang 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 Clang module
module load Clang

#Check Clang version
clang --version

#Compile C program with Clang
clang 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=clang

# These are the options we pass to the compiler.
# -std=c++1y means we want to use the C++14 standard (called 1y in this version of Clang).
# -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++1y -stdlib=libc++ -c -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 Clang module
module load Clang

#Check Clang version
clang --version

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

#Execute the program
hello_c