There are a number of tools to build an application. Very often make or cmake is used to build applications with different complexity.
To use Make, you have to manually create the Makefile, but with CMake, the Makefile is automatically created.
Environmental Modules & Makefile
It is quite handy to use environmental modules and load different version of libraries, but how to make use of these ever changing PATHs. Take a look at the following examples to help with making your Makefile ready for modules.
Makefile
123456789
# use the environmental variable $INCLUDE or $CPATH# split the paths separated by :INC=$(subst:,,$(INCLUDE))INC=$(subst:,,$(CPATH))# add a -I/path/to/includeINC:=$(INC:%=-I%)# use the environmental variable $LIBRARY_PATHLIBS=$(subst:,,$(LIBRARY_PATH))LIBS:=$(LIBS:%=-L%)
With this code snippet in your Makefile you should be able to use environmental variables such as $INCLUDE/$CPATH or $LIBRARY_PATH efficiently. These paths adapt to your loaded modules.
There is also the possibility to hard code the path of the libraries into the executable.
Makefile
123456789
# use the environmental variable $CPATH# split the paths separated by :INC=$(subst:,,$(CPATH))# add a -I/path/to/includeINC:=$(INC:%=-I%)# use the environmental variable $LIBRARY_PATHLIBPATH:=$(subst:,,$(LIBRARY_PATH))LIBRPATH:=$(LIBPATH:%=-Wl,-rpath=%)LIBPATH:=$(LIBPATH:%=-L%)
This allows the user to not load any libraries when running the application, as the path to the libraries is fixed.
Cmake
When using cmake these paths are found automatically.
important is when writing a makefile is to use tabs