This page explains how to compile a program that uses Bio++ (source file biohello.cpp) using g++. It is intended at linux users primarily.
In this example we assume that the libraries binaries (.so and/or .a files) are located in directory $HOME/.local/lib and that the library includes tree (.h files) are located in directory $HOME/.local/include. Because these places are non-standard (ie. not /usr/local/lib) they must be passed to the compiler through the -L and -I parameters.
- The CPATH/CPLUS_INCLUDE_PATH and LIBRARY_PATH environment variables can be used instead of the -I and -L parameters, respectively.
- Programs compiled with dynamic linkage will not run without runtime access to the libraries (.so files). If the libraries are installed in a non-standard place (ie. not /usr/local/lib), this place must be added to the runtime LD_LIBRARY_PATH environment variable.
<source lang="bash"> g++ -I$HOME/.local/include \
-L$HOME/.local/lib \ -lbpp-core -lbpp-seq -lbpp-phyl -lbpp-popgen \ -o biohello \ biohello.cpp
</source> Here the five libraries are included, you may omit the two last ones if you do not use phylogenetic and/or population genetics classes.
When compiling with static linkage, the order of the libraries to include is important: <source lang="bash"> g++ --static
-I$HOME/.local/include \ -L$HOME/.local/lib \ -lbpp-popgen -lbpp-phyl -lbpp-seq -lbpp-core \ -o biohello \ biohello.cpp
strip biohello </source> Here again you may omit the PopGen and Phyl libraries.
Programs compiled with static linkage are stand-alone programs and do not require the libraries to be present when running. The strip command removes all unused code from the executable, and efficiently decreases its size.