Compiling Software¶
Overview¶
On the clusters you will frequently need to build software from source. This guide shows how to use the GNU Build System (Autotools), plain make, and cmake to configure, compile, and install programs in your user space.
Autotools (GNU Build System)¶
The classic GNU Build System is based on two key pieces:
- a
configurescript that adapts the build to the current machine - one or more
Makefiles that describe how to build and install the software withmake.
In practice, building many Autotools-based packages on the cluster boils down to the standardized three-step sequence:
This is exactly the pattern described in the GNU Build System documentation: configure probes the system and writes Makefiles with the right compiler, flags and paths, and each run of make then checks what needs to be rebuilt before executing the corresponding rules.
Some tips when using Autotools on the cluster:
- Out-of-tree builds: When possible, build in a separate directory to keep the source tree clean.
- Prefix per user: Keep
--prefixinside your home directory (for example$HOME/software/mytool) so you do not need administrator privileges. - Re-configuring: If you change compilers or important environment variables, re-run
./configureso the generatedMakefiles match the new environment.
Make¶
make is the core tool that executes the build rules described in a Makefile. On the clusters you will see it both as part of the GNU Build System (./configure && make && make install) and in simpler projects that ship only a hand-written Makefile.
-
Compiling a Project with Make: With a suitable
Makefilein the project directory, start the compilation with: -
Customizing the Build: You can pass variables on the command line to choose compilers or optimization flags, for example:
-
Installing (when supported): Some
Makefiles also provide an install target similar to Autotools. In those cases you might see:
Always check the project’s documentation or run make help to see which targets are available.
CMake¶
-
Loading CMake: To use CMake on the cluster, first load the corresponding module:
-
Configuring and Compiling a Project with CMake:
-
Create a build directory:
-
Run CMake to configure the project, specifying the source directory:
-
After configuration, compile the project with:
Problems and Support¶
If you encounter issues when using Make or CMake to compile software, please refer to our support page for assistance.