FAQ: Boost on HPC Systems


There are boost modules available on our systems. But they might not be adequate because of the wrong version, or incompleteness of features. Or, you may just want to use a different compiler.

Recipe to build and use it

  1. Download the desired boost version from https://www.boost.org/  Or, if internet is available: 
    git clone --recurse-submodules https://github.com/boostorg/boost.git
    cd boost
    git tag                           # select the desired tag
    git checkout boost-1.88.0         # for instance
  2. Load the compiler and MPI modules (if MPI is required; if not, skip it in the following); can be gcc, intel/oneapi/llvm and Intel MPI, MPICH, OpenMPI
    Just go sure that your compiler supports reasonably a modern C++ standard!
    Load a relatively new cmake!
  3. Configure (here, we do that using gcc/13.2.0 and intel-mpi/2021.10.0):
    ./bootstrap.sh --with-toolset=gcc --with-libraries=atomic,chrono,context,date_time,exception,fiber,filesystem,headers,iostreams,locale,log,math,nowide,program_options,random,regex,serialization,stacktrace,system,test,thread,timer,type_erasure

    Check boost's documentation for available toolsets (clang, intel, gcc are probably the mostly used ones) and for available libraries (also check the libs sub-directory in boost's sources). Of course, you don't need to install all of them! Just what you need! We just gave some examples here.
    With that, the b2 tool is build, required for building and installing boost.
    Remark: The tool chain has nothing to do which compiler you later want to use. It is solely about with which compiler to build boost. So, system gcc is most probably fine for all cases unless you desire some higher C++ standard later maybe not supported by this compiler.
    Remark: One can execute ./bootsrap.sh also without any option. Then, only the b2 tool is built. Using ./b2 --show-libraries reveals all available libraries that can be build in boost.
  4. Installing boost:
    ./b2 --prefix=<boost-install-path>/boost_1.88.0 cxxflags="-std=c++17" variant=release,debug link=shared threading=multi runtime-link=shared address-model=64 -j 20 install

Both, bootstrap and b2 have both --help option and online documentation.

Usage

The simples way to use boost libraries in own C++ projects is through CMake's find_package. An example is given here. Again, only the needed parts need be included.

For using your just installed boost library, direct both LD_LIBRARY_PATH and CMAKE_PREFIX_PATH to the lib and lib/cmake path, respectively. <boost-install-path>/boost_1.88.0/lib and <boost-install-path>/boost_1.88.0/lib/cmake in our example. CMake's find_package should then find everything.

Remarks

  • Boost seems to contain also a CMakeLists.txt. That may simplify boost's installation procedure further.
  • Note that boost is permanently evolving. And many parts are also migrated already into the C++ STL (and standard library). That is each version of boost may possess different features.