Setting up the Boost C++ library

Windows

Download and unzip the latest Boost C++ library (version 1.65.0 at this writing). You can unzip the boost_1_65_0.zip file anywhere on your hard drive. I created a directory named libraries inside This PC\Documents where I keep all libraries associated with this project. Important: to keep things simple, I will assume that you will also place all libraries into the This PC\Documents\libraries folder. After unzipping the Boost library, for example, I now have a directory named This PC\Documents\libraries\boost_1_65_0. (I strongly recommend using the program 7-zip to unzip the downloaded zip file because otherwise it may take hours to unzip it.)

Some of the libraries within Boost that we will be using need to be compiled, so let’s do that now. Start by double-clicking the This PC\Documents\libraries\boost_1_65_0\bootstrap.bat file. This will create the compile engine that Boost uses (called b2.exe) and will deposit a file named project-config.jam in the This PC\Documents\libraries\boost_1_65_0 directory. This file will contain 3 lines, but edit it (use NotePad++ for this) and add one additional line that specifies the libraries we will need compiled:

import option ; 
using msvc ; 
option.set keep-going : false ; 
libraries = --with-program_options --with-regex --with-filesystem --with-system ;

Important! Be sure to leave a space before the semicolon (;) that terminates each line.
Not adding the “libraries” line will result in a very long wait because Boost will proceed to compile all libraries that need to be compiled. There is nothing wrong with compiling everything (you may need it later), so feel free to just use the default project-config.jam if you want.

To start the compile process, Shift-right-click on the boost_1_65_0 directory and choose Open command window here from the popup menu, then type

b2.exe link=shared

If all goes well, you should see this when the program exits:

The Boost C++ Libraries were successfully built!

The following directory should be added to compiler include paths:

    C:\boost_1_65_0

The following directory should be added to linker library paths:

    C:\boost_1_65_0\stage\lib

Now we need to tell Visual Studio about the Boost library so that we can use Boost header files and compiled libraries in our project.

  • Right-click the strom project (note: click the project, not the solution) in the Solution Explorer pane of Visual Studio and choose Properties from the popup menu.
  • Expand VC++ Directories, then click on Include Directories, then click the down-pointing triangle, then click <Edit…> and add This PC\Documents\libraries\boost_1_65_0.
  • While you are in VC++ Directories, click Library Directories and add This PC\Documents\libraries\boost_1_65_0\stage\lib.
  • In the C/C++ Preprocessor section, add BOOST_ALL_DYN_LINK to the Preprocessor Definitions. This ensures that Visual Studio will use dynamic linking for boost libraries (which matches the link=shared flag we provided to b2 when compiling the boost libraries)

Mac

Download the latest Boost C++ library (version 1.65.0 at this writing). You should be able to unpack the (boost_1_65_0.zip or boost_1_65_0.tar.gz) archive by simply double-clicking the file name, then move the resulting unpacked directory to the location of your choice. I created a folder named libraries inside my Documents folder where I keep all libraries associated with this project. Important: to keep things simple, I will assume that you will also place all libraries into the Documents/libraries folder. After unzipping the Boost library, for example, I now have a directory named Documents/libraries/boost_1_65_0.

Some of the libraries within Boost that we will be using need to be compiled, so let’s do that now. Start by opening a terminal and navigating to your Documents/libraries/boost_1_65_0 directory (on my computer it is located in /Users/plewis/Documents/libraries/boost_1_65_0):

cd /Users/plewis/Documents/libraries/boost_1_65_0

Now run the bootstrap script:

./bootstrap.sh --with-toolset=clang --with-libraries=program_options,regex,filesystem,system

This will create the compile engine that Boost uses (called b2) and will deposit a file named project-config.jam in the boost_1_65_0 directory.
Not adding the --with-libraries option will result in a very long wait because Boost will proceed to compile all libraries that need to be compiled. There is nothing wrong with compiling everything (you may need it later), so feel free to leave this command line option off.

To start the compile, run b2

./b2

If all goes well, you should see this when the program exits (except for the /Users/plewis/Documents/libraries part, of course):

The Boost C++ Libraries were successfully built!

The following directory should be added to compiler include paths:

    /Users/plewis/Documents/libraries/boost_1_65_0

The following directory should be added to linker library paths:

    /Users/plewis/Documents/libraries/boost_1_65_0/stage/lib

Now we need to tell Xcode about the Boost library so that we can use Boost header files and libraries in our project.

Source Trees

  • Choose Xcode > Preferences… from the main menu, then choose the Locations tab, then click the Source Trees subtab.
  • Click the + button and add a new Source Tree item named BOOST_ROOT with display name BOOST_ROOT and Path equal to the path to your Boost main directory. For me, that is /Users/plewis/Documents/libraries/boost_1_65_0
  • Click the red button at the top left to close the preferences dialog box.

Build Settings

  • Click once on the strom project (with the blue icon, not the yellow folder icon) in the Project Navigator pane. You should now see Build Settings, Build Phases, and Build Rules across the top of the right-hand pane.
  • Click on Build Settings, All (not Basic), Levels (not Combined), and then type “header search” into the Search box to filter out all build settings except those we are interested in at the moment.
  • Click on Header search paths row, then double-click on the column labeled strom that has a blue icon (this is the column for the project settings, the other column labeled strom contains target-specific settings).
  • Click the + button at the bottom left corner and type $(BOOST_ROOT) (this will expand to the source tree you defined above).
  • While you are in Build Settings, type “library search” into the Search box and then double-click on the row labeled Library Search Paths (column labeled strom with blue icon again).
  • Click the + button at the bottom left corner and type $(BOOST_ROOT)/stage/lib.

Build Phases

  • Now switch to Build Phases, expand “Link Binary With Libraries”, press the + button, click Add Other…, then select all 4 dylib files in your boost_1_65_0/stage/lib directory (libboost_filesystem.dylib, libboost_system.dylib, libboost_regex.dylib, and libboost_program_options.dylib).

Scheme

  • Finally, at the top of the Xcode window, to the right of the ▶ (run program in debugger) and ◙ (stop program running in debugger) buttons, click on the button labeled strom (attached to the button labeled My Mac).
  • Choose Edit Scheme… from the popup menu, then choose the Arguments tab and click the + button under Environmental Variables
  • Type DYLD_LIBRARY_PATH into the Name field, and $(BOOST_ROOT)/stage/lib into the Value field.
  • Close the dialog box using the Close button at the bottom right and you should be good to go