Compiling and Linking on XC40

When you compile your code for our XC40 systems, you are normally cross-compiling for the compute nodes (Intel Xeon Phi 2nd Generation [KNL]), rather than directly compiling for the login nodes (non-KNL). By default, you are using the Intel compiler suite. We also provide the Cray, GNU, and Clang compiler suites via modules.

Wrapper Command Names

Regardless of which compiler suite you use, you must use the standard Cray compiler wrapper names, which will automatically include MPI and other dependencies:

  • cc – for C codes
  • CC – for C++ codes
  • ftn – for Fortran codes

Do not use the mpicc, mpiCC or mpicc++, or mpif77 or mpif90 wrappers. They exist on the XC40 and are callable, but will not produce code for the compute nodes.


The following are examples to compile and link a hello.c C-source program, hello.cpp C++ source program, and hello.f Fortran source program into an executable hello:

cc -g -O -o hello hello.c
CC -g -O -o hello hello.cpp
ftn -g -O -o hello hello.f

You should always include the -g option regardless of the optimization level. It does not impact performance and allows tools to map to your source code to provide call stacks, etc.


Generally, you should use the compiler wrappers to invoke the linker indirectly, when linking object files.

Man Pages

There are man pages for the wrappers:

man cc
man CC
man ftn

which explain how options to specific underlying compiler suites, such as Intel, are passed through. For detailed man pages about the specific compiler suites, you must specify the names of the specific compilers:


man icc (C++/C)
man ifort


man craycc
man crayCC
man crayftn


man gcc
man g++
man gfortran

LLVM/Clang (Fortan not yet available)

clang --help
clang++ --help

Switching Compiler Suites

Use modules to select different compiler suites. To change from the default Intel suite to one of the three others available, use one of these commands:

module swap PrgEnv-intel PrgEnv-cray
module swap PrgEnv-intel PrgEnv-gnu
module swap PrgEnv-intel PrgEnv-llvm

Compiling for Login Nodes

The login nodes are not for computing. If you need to build a tool or utility to run on the login nodes, you should directly invoke the compilers in whichever suite you are using.