Reference Documentation
The following exercises will help you understand how to build your own software on the ATOS HPCF or ECS.
Building a simple program
Ensure your environment is clean by running:
module reset
Create a directory for this tutorial and cd into it:
mkdir -p compiling_tutorial cd compiling_tutorial
We are going to use a simple program that will display versions of different libraries linked to it. Create a file called
versions.c
using your favourite editor with the following contents:Try to naively compile this program with:
$CC -o versions versions.c
- The compilation above fails as it does not know where to find the different libraries. We need to add some additional flags so the compiler can find both the include headers and link to the actual libraries.
Let's use the existing software installed on the system with modules, and benefit from the corresponding environment variables *_DIR which are defined in them to manually construct the include and library flags:
$CC -o versions versions.c -I$HDF5_DIR/include -I$NETCDF4_DIR/include -I/$ECCODES_DIR/include -L$HDF5_DIR/lib -lhdf5 -L$NETCDF4_DIR/lib -lnetcdf -L$ECCODES_DIR/lib -leccodes
Load the appropriate modules so that the line above completes successfully and generates the
versions
executable:Run
./versions
. You will get an error such as the one below:$ ./versions ./versions: error while loading shared libraries: libhdf5.so.200: cannot open shared object file: No such file or directory
While you passed the location of the libraries at compile time, the program cannot not find the libraries at runtime. Inspect the executable with
ldd
to see what libraries are missingCan you make that program run successfully?
Can you rebuild the program so it uses the "old" versions of all those libraries in modules? Ensure the output of the program matches the versions loaded in modules? Do the same with the latest.
To simplify the build process, let's create a simple Makefile for this program. With your favourite editor, create a file called
Makefile
in the same directory with the following contents:You can test it works by running:
make clean ldd test
Using different toolchains: prgenv
So far we have used the default compiler toolchain to build this program. Because of the installation paths of the library, it is easy to see both the version of the library used as well as the compiler flavour with ldd:
$ make ldd libhdf5.so.200 => /usr/local/apps/hdf5/<HDF5 version>/GNU/8.5/lib/libhdf5.so.200 (0x000014f612b7d000) libnetcdf.so.19 => /usr/local/apps/netcdf4/<NetCDF version>/GNU/8.5/lib/libnetcdf.so.19 (0x000014f611f2a000) libeccodes.so => /usr/local/apps/ecmwf-toolbox/<ecCodes version>/GNU/8.5/lib/libeccodes.so (0x000014f611836000)
Rebuild the program with:
- The default GNU GCC compiler.
- The default Classic Intel compiler.
- The default LLVM-based Intel compiler.
- The default AMD AOCC.
Use the following command to test and show what versions of the libraries are being used at any point:
make clean ldd test