Using Boost on the CS Linux Machines

Current configurations for our classroom/lab machines include multiple versions of the Boost libraries:

Compiling and running programs using Boost

Default version

If you're using the default version of everything (compiler(s) and Boost libraries), then everything should “just work” if you remember to include the appropriate #include directive(s) in your source code and link with any needed libraries (-l flag(s) to g++). The project Web site (link below) should have more information about specifics.

Latest version

The simplest way to access the most recent non-default version is to use the command

module load boost-latest
(See my notes on the “Modules package” for more about the module command.)

It's probably safest to also use the latest compilers, as described in my notes on the GNU compilers.

You'll also need to pass to g++ the following flags:

-I $(BOOSTROOT)/include -L $(BOOSTROOT)/lib
($BOOSTROOT is an environment variable set by that module load command.) You may also need the flag -lboost_thread-mt, and if you're using Boost's thread library you'll need -pthread. If you're using make to compile, (as described in my notes on the GNU compilers), the right way to add these flags is with a Makefile such as the following (also using my preferred optional flags):
CXXFLAGS=-std=c++17 -Wall -pedantic -pthread -O -I $(BOOSTROOT)/include
Be advised that doing this may result in warnings caused by compiling library code. Adding the following flags to the line starting CXXFLAGS= seems to work well in suppressing them but allowing other warnings:
-Wno-unused-local-typedefs -Wno-deprecated-declarations -Wno-unused-variable -Wno-placement-new
This makes for a very long line; you can break it across multiple lines by ending lines with a backslash (\).

Support for MPI

Non-default versions are also configured with support for the MPI-related Boost functions/libraries. To use this feature, you'll also need to set up to use a more-recent-than-default version of MPI, as described in my notes on MPI. If at runtime you encounter errors that seem to indicate that the program cannot find the needed libraries, it may help to compile with the following additional flags:

(If using a Makefile, add this to the line starting CXXFLAGS=.)

Useful links