From Documentation
Revision as of 15:11, 8 July 2014 by Preney (Talk | contribs) (Compiling Your Own Version Of Boost)

Jump to: navigation, search
Description: free peer-reviewed portable C++ source libraries
SHARCNET Package information: see BOOST software page in web portal
Full list of SHARCNET supported software

Operating System Installed Boost

The version of boost and boost-devel packages installed are provided with the native operating system and not provided by a SHARCNET module hence they are available by default.

To get the latest version information about the packages do:

rpm -qi boost
rpm -qi boost-devel

To get a listing of files for each package do:

rpm -ql boost
rpm -ql boost-devel

Compiling Your Own Version Of Boost

Unfortunately, the operating system-installed version of the Boost libraries are usually out of date and programs relying on boost libraries may require a later version. Please check the documentation of the package you are trying to link to boost libraries to see which version is the minimum required. If this minimum is later than the native system libraries, you will have to install the newer boost libraries on your own.

Manually Building Boost

The following are the steps to manually build Boost from the command-line.

  1. Download Boost from
  2. Extract the file downloaded into an empty directory using one of these commands:
    • unzip boost_VERSION.tar.gz
    • tar xvzf boost_VERSION.tar.gz
    • tar xvjf boost_VERSION.tar.bz2
    • NOTE: This top directory holding the uncompressed Boost files will be called $BOOST_SRC below.
  3. Decide on which C++ compiler you are going to use (e.g., GCC, Intel, PGI). Once that is done, use SHARCNET's module system to unload any previous compiler and load the one you need:
    • Unload C++ compiler modules: module unload gcc intel pgi
    • Load the GCC v4.8.2 module example: module load gcc/4.8.2
  4. Decide on whether or not you want MPI support (and load the one suitable for the compiler you've chosen):
    • Unload the module: module unload openmpi
    • Load MPI for GCC example: module load openmpi/gcc (Omit this line if you don't need MPI.)
  5. Decide whether or not you need Python support (and load the one suitable for the compiler you've chosen).
    • Unload the module: module unload python
    • Load Python for GCC module: module load python/gcc (Omit this line if you don't need Python.)
    • NOTE: Boost will use the system's Python if you don't load the module which is okay if you don't need Python.
  6. Change the directory to $BOOST_SRC:
    • cd $BOOST_SRC
  7. NOTE: Because SHARCNET has many compilers and tools available, avoid using the shortcut method to building Boost --build Boost's b2 program instead.
  8. Change the directory to build bjam:
    • cd tools/build/v2
  9. For the aforementioned selected C++ compiler, determine the correct --with-toolset option for
    • ./ --with-toolset=help (This command is designed to fail.)
    • less booststrap.log
  10. Replace TOOLSET_NAME_FROM_FILE with the appropriate toolset mentioned in the bootstrap.log file and the run:
    • ./ --with-toolset=TOOLSET_NAME_FROM_LOG_FILE
    • e.g., ./ --with-toolset=gcc
    • e.g., ./ --with-toolset=intel-linux
    • e.g., ./ --with-toolset=pgi
  11. Decide on a directory you want to install Boost build into.
    • This directory will be referred to as $BUILD_DIR below.
  12. Run:
    • ./b2 install --prefix=$BUILD_DIR
  13. Add $BUILD_DIR/bin to your PATH (in your shell):
    • export PATH
  14. If you need Boost MPI, then add the following text to a line of its own in user-config.jam:
    • using mpi ;
  15. Go back up to the $BOOST_SRC directory:
    • cd ../../..
  16. Decide on an empty directory where you want to install the Boost libraries.
    • This directory will be referred to as $INSTALL_DIR below.
  17. If you would like Boost to build its libraries in parallel, decide on the number of parallel processes.
    • This number will be referred to as $NUM_PROCS below.
  18. Although it is usually the same as the above, determine the toolset (referred to as $TOOLSET below) you need from the Boost documentation:
  19. Build the Boost libraries by running:
    • Normal sequential build: b2 --prefix=$INSTALL_DIR --build-dir=$BUILD_DIR toolset=$TOOLSET install
    • Parallel build: b2 -j$NUM_PROCS --prefix=$INSTALL_DIR --build-dir=$BUILD_DIR toolset=$TOOLSET install
  20. If all of the above went well, you're done building Boost!

NOTE: b2 and the code in $BUILD_DIR is only needed to build Boost. You can delete $BUILD_DIR after Boost has been built by running rm -rf $BOOST_DIR.

Compiling and Linking to the Boost Libraries + Running Executables

Please note the following:

  • The INCLUDE directory for Boost is $BOOST_HOME/include.
  • The LIBRARY directory for Boost is $BOOST_HOME/lib.

To build programs use the -I, -L, and -l options to specify the top include file directory, the top library directory and any specific libraries that must be linked in to your program, e.g.,

  • A program that uses header-only libraries: $CXX -I $BOOST_HOME/include program1.cxx
  • A program that uses the Boost regex library: $CXX -I $BOOST_HOME/include -L $BOOST_HOME/lib -lboost_regex program2.cxx
  • etc.

If your $BOOST_HOME is not in a system-wide library directory, your compile program won't run. You can ensure it does run by adding $BOOST_HOME/lib to your LD_LIBRARY_PATH (once per shell) as follows:

  • export LD_LIBRARY_PATH

and now you will be able to sucessfully run your programs.

Finally remember to BEFORE running your programs you will ALWAYS need to "module unload" and "module load" the settings for any new shells you create. This can be a nuisance --you might prefer to place those unload and load commands at the bottom of your ~/.bashrc file.


o Boost Homepage