[HOWTO] compile a software in your home directory

In this howto I’ll explain how to use a library provided by module and then how to compile as user a software on Baobab using this library.

On the cluster, a lot of libraries are provided by EasyBuild through module. In this howto, we’ll use zlib as example library.

First, load a compiler and the libraries:

module load foss/2018b zlib

If the library module is well written, you can use pkg-config to get the correct flags for compiler and linker.

For example to get the include path for the z library:

pkg-config zlib --cflags
-I/opt/ebsofts/Compiler/GCCcore/7.3.0/zlib/1.2.11/include

You can get as well the output for the linker:

pkg-config --libs zlib
-L/opt/ebsofts/Compiler/GCCcore/7.3.0/zlib/1.2.11/lib -lz

Depending on your build system, it’s maybe even not needed to add the include path as it’s already defined when you load the module. You can see that with a module command:

module show zlib
[...]
prepend_path("CPATH","/opt/ebsofts/Compiler/GCCcore/7.3.0/zlib/1.2.11/include")
prepend_path("LD_LIBRARY_PATH","/opt/ebsofts/Compiler/GCCcore/7.3.0/zlib/1.2.11/lib")
[...]

The output of module show may be useful as well if you need to figure out where the files are stored.

Let’s take a full example by compiling subread-1.6.4 from source as user in your home directory on Baobab. This soft needs a more recent version of zlib than provided by the system.

Download the source code:

wget https://downloads.sourceforge.net/project/subread/subread-1.6.4/subread-1.6.4-source.tar.gz

Decompress the archive:

tar xf subread-1.6.4-source.tar.gz

Load a recent compiler and zlib:

module load foss/2018b zlib

Go to the src directory:

cd subread-1.6.4-source/src

Edit the Makefile.Linux file to indicate the location of zlib. Replace the string -lz by $(shell pkg-config --libs zlib).

You can now build the software:

make -f Makefile.Linux

That’s it. The executable are copied to ../bin

HTH

1 Like

If the library you are using doesn’t provide a pkg-config file, you can use as well the variables set by module load, such as $EBROOTXXX where XXX is the name of the module. XXX should be written in caps. Example for OpenBLAS:

module load foss/2019b
[sagon@login2 gevpp][master] $ echo $EBROOTOPENBLAS
/opt/ebsofts/OpenBLAS/0.3.7-GCC-8.3.0