LAPACK relies on BLAS to provide more complicated linear algebra routines for e.g. solving systems of linear equations and linear least squares, eigenvalue problems, or matrix factorizations such as LU.
Many different implementations of BLAS and LAPACK exist. A commonly used one is OpenBLAS, which contains both BLAS and LAPACK in one library file. I.e. if one uses OpenBLAS it suffices to add
-lopenblasto link in support for both BLAS and LAPACK functions.
In other implementations BLAS and LAPACK are in separate libraries and then one usually adds
-lblas -llapackto link in support for BLAS and LAPACK functions.
module load openblasbefore compiling. Then the -L and -I options do not need to be given, and configurations such as MyConfig simplify.
This works because the module system will set the environment variables LIBRARY_PATH and CPATH that the gcc compiler uses (if no -L or -I are given) to search for libraries and include files. You can verify that they have been set with:
echo $LIBRARY_PATH echo $CPATHThe module system should also set the environment variable LD_LIBRARY_PATH. LD_LIBRARY_PATH is not directly used by the compiler. Rather it is used at program start to find all shared libraries that the program needs. Check it with:
echo $LD_LIBRARY_PATHIf only LD_LIBRARY_PATH is wrong, the compilation will succeed, but when you start the compiled program, you may get "error while loading shared libraries".
Unfortunately, on FAU's Athene supercomputer some of these modules are broken in the sense that they do not set all required environment variables, so that one still may need to specify some -L and -I options anyway. For some libraries we can find out these options using pkg-config. E.g.
pkg-config --libs openblas pkg-config --cflags openblasshould tell us the locations for openblas. When pkg-config works on Athene, we can even use
SPECIALLIBS += $(shell pkg-config --libs openblas)directly in the MyConfig. But on Athene you never know if a module sets up the environment variables that pkg-config needs, so that pkg-config may fail as well.