Basic compilation

From Bio++ Wiki
Jump to: navigation, search

This page explains how to compile a program that uses Bio++ (source file biohello.cpp) using g++.


In this example we assume that the libraries binaries (.so and/or .a files) are located in directory $HOME/local/bpp/dev/lib and that the library includes tree (.h files) are located in directory $HOME/local/bpp/dev/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.

<source lang="bash"> bpp_dir=$HOME/local/bpp/dev </source>

Dynamic linkage

<source lang="bash"> g++ biohello.cpp \

   -o biohello \
   -I$bpp_dir/include \
   -L$bpp_dir/lib \
   -lbpp-popgen -lbpp-phyl -lbpp-seq -lbpp-core

</source>

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.

Static linkage

<source lang="bash"> g++ biohello.cpp \

   -o biohello \
   --static \
   -I$bpp_dir/include \
   -L$bpp_dir/lib \
   -lbpp-popgen -lbpp-phyl -lbpp-seq -lbpp-core

strip biohello </source>

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.

Remarks
  • Where on the command line and in which order the libraries are included (-l options) does matter.
  • The CPATH/CPLUS_INCLUDE_PATH and LIBRARY_PATH environment variables can be used instead of the -I and -L parameters, respectively.