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.)
Hereafter, I will refer to the Boost folder as BOOST_ROOT. Whenever you see BOOST_ROOT in these instructions, you should replace it with This PC\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 double-clicking the BOOST_ROOT\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 BOOST_ROOT 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
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
stromproject (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 BOOST_ROOT.
- While you are in VC++ Directories, click Library Directories and add BOOST_ROOT\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)
Making the DLLs available at run time
You now have a choice: do one of the following two things to ensure that Boost DLLs will be available to your program when it runs:
- Edit the system environmental variable
Pathso that it begins with the directory BOOST_ROOT\stage\lib (remember, BOOST_ROOT should be replaced by the actual Boost folder path; e.g. type This PC\Documents\libraries\boost_1_65_0\stage\lib, not BOOST_ROOT\stage\lib). Be sure to separate it from the next directory specified in
Pathby a semicolon (;). To modify system environmental variables, on Windows 10 click the Start button, then Settings, type the word "Environment" into the search box, select Edit the system environmental variables, click the Environmental Variables… button, select
Pathin the list of System variables, press the Edit… button, and type in the directory containing the 4 Boost DLL files (boost_filesystem-vc141-mt-1_65_1.dll,
boost_program_options-vc141-mt-1_65_1.dll,boost_regex-vc141-mt-1_65_1.dll, and boost_system-vc141-mt-1_65_1.dll).
- Copy the 4 Boost DLL files boost_filesystem-vc141-mt-1_65_1.dll,
boost_program_options-vc141-mt-1_65_1.dll,boost_regex-vc141-mt-1_65_1.dll, and boost_system-vc141-mt-1_65_1.dll from BOOST_ROOT\stage\lib to the Debug directory containing your strom.exe file. Important: the Debug directory will only be created in your project directory once you’ve compiled your program for the first time (end of Part 2), so if you choose this option you will need to defer this step until the Debug directory is created. I will remind you when the time comes to revisit this page.
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):
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
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.
- 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_ROOTwith display name
BOOST_ROOTand 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.
- 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
- 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).
- 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
DYLD_LIBRARY_PATHinto the Name field, and
$(BOOST_ROOT)/stage/libinto the Value field.
- Close the dialog box using the Close button at the bottom right and you should be good to go