You will need to understand how to use the terminal.

Note

This section is a short introduction in case you are missing a few software packages, want to try out a cutting edge development version of a software or have no system administrator or software package manager to build and install software for you.

# Compiling from Source¶

Don’t be afraid young physicist, self-compiling C/C++ projects is easy, fun and profitable!

Compiling a project from source essentially requires three steps:

1. configure the project and find its dependencies
2. build the project
3. install the project

All of the above steps can be performed without administrative rights (“root” or “superuser”) as long as the install is not targeted at a system directory (such as /usr) but inside a user-writable directory (such as $HOME or a project directory). ## Preparation¶ In order to compile projects from source, we assume you have individual directories created to store source code, build temporary files and install the projects to: # source code mkdir$HOME/src
# temporary build directory
mkdir $HOME/build # install target for dependencies mkdir$HOME/lib


Note that on some supercomputing systems, you might need to install the final software outside of your home to make dependencies available during run-time (when the simulation runs). Use a different path for the last directory then.

## Step-by-Step¶

Compling can differ in two principle ways: building inside the source directory (“in-source”) and in a temporary directory (“out-of-source”). Modern projects prefer the latter and use a build system such as [CMake]. An example could look like this

# go to an empty, temporary build project
cd $HOME/build rm -rf ../build/* # configurate, build and install into$HOME/lib/project
cmake -DCMAKE_INSTALL_PREFIX=$HOME/lib/project$HOME/src/project_to_compile
make
make install


Often, you want to pass further options to CMake with -DOPTION=VALUE or modify them interactively with ccmake . after running the initial cmake command. The second step which compiles the project can in many cases be parallelized by make -j. In the final install step, you might need to prefix it with sudo in case CMAKE_INSTALL_PREFIX is pointing to a system directory.

Some older projects still build in-source and use a build system called autotools. The syntax is still very similar:

# go to the source directory of the project
cd $HOME/src/project_to_compile # configurate, build and install into$HOME/lib/project
configure --prefix=\$HOME/lib/project
make
make install


That’s all! Continue with the following chapter to build our dependencies.

## References¶

 [CMake] Kitware Inc. CMake: Cross-platform build management tool, http://cmake.org/