Download and install the latest Boost C++ library (version 1.59.0 at this writing). (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 C:\boost_1_59_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 C:\boost_1_59_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_59_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_59_0 The following directory should be added to linker library paths: C:\boost_1_59_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 C:\boost_1_59_0.
- While you are in VC++ Directories, click Library Directories and add C:\boost_1_59_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)
Download the latest Boost C++ library (version 1.59.0 at this writing). You should be able to unpack the (zip or tar.gz) archive by simply double-clicking the file name, then move the resulting unpacked directory to the location of your choice.
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 the boost_1_59_0 directory, which on my computer is located in /Users/plewis/Documents/libraries:
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_59_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_59_0 The following directory should be added to linker library paths: /Users/plewis/Documents/libraries/boost_1_59_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_59_0
- Click the red button at the top left to close the preferences dialog box.
- Click once on the strom target (not the folder) 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 paths” 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 paths” 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_59_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