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++. It is intended at linux users primarily.


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

Dynamic linkage

<source lang="bash"> g++ -I/home/vador/local/include \

   -L/home/vador/local/lib \
   -lbpp-core -lbpp-seq -lbpp-phyl -lbpp-popgen biohello.cpp \
   -o biohello

</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.

Programs compiled with dynamic linkage will not run without runtime access to the libraries (.so files). The directories in which libraries are, if non-standard (ie. not /usr/local/lib), must be added to the runtime LD_LIBRARY_PATH environment variable.

Static linkage

When compiling with static linkage, the order of the libraries to include is important: <source lang="bash"> g++ --static

   -I/home/vador/local/include \
   -L/home/vador/local/lib \
   biohello.cpp -lbpp-popgen -lbpp-phyl -lbpp-seq -lbpp-core \
   -o biohello

strip biohello </source> Here again you may omit the PopGen and Phyl libraries. The strip command removes all unused code from the executable, and efficiently decreases its size.

Programs compiled with static linkage are stand-alone programs and do not require the libraries to be present when running.