Building boost on Windows 10 for Visual Studio 2017

I recently started using boost libraries in a C++ project. Wanting to reduce overheads when compiling projects, I decided to build and link the libraries in Visual Studio. There were a few problems when following the instructions on boost (for starters, we are building 1.68, not 1.67). These problems and my solutions are detailed here.

Getting and building boost

  1. Download 1.68.0 (download link). The rest of these steps assume it is downloaded to the default directory C:\Users\username\Downloads\
  2. Unzip it (if you don’t have it, get 7zip here)
  3. Launch cmd prompt in the unzipped directory (you won’t need Administrator privileges)
  4. Run bootstrap.bat
  5. Run .\b2

This will create the build libraries in C:\Users\username\Downloads\boost_1_68_0\stage\lib\.

The last lines of output from Step 5 should say:

The Boost C++ Libraries were successfully built!

The following directory should be added to compiler include paths:


The following directory should be added to linker library paths:


And this is far more help than you get in the documentation!

Linking to boost in Visual Studio

I copied and pasted the C:\Users\username\Downloads\boost_1_68_0\boost and C:\Users\username\Downloads\boost_1_68_0\stage directories into C:\Program Files\boost\boost_1_68_0. This is the path suggested in the boost getting started guide. It does not appear that you need any other of the files from the boost directory that was downloaded and built.

2018-11-11 11_56_04-boost_1_68_0.png
The final build directories in the recommended path

These need to be linked in the following places in the properties of a project in Visual Studio:

2018-11-10 08_25_25-vs-boost-built-starter Property Pages
Additional library directories in Visual Studio
2018-11-10 08_24_46-vs-boost-built-starter Property Pages
Additional include directories in Visual Studio

This should then enable you to start using boost! I’ve created a starter project on Github so that the above steps don’t need to be repeated again. It uses the simple regex example from the starter guide to show that the libraries have been correctly linked.

Other problems

One issue, which I will write a separate article about, is that Visual Studio creates its initial source code files in any project in UCS-2 LE BOM encoding. This means that Git does not pick it up as a text file and assumes it is binary, making code changes unmanageable. I still haven’t gotten to the bottom of why this occurs, but it can be fixed by opening the file in Notepad++ and changing the encoding to UTF-8 from the Encoding menu.

Other than this, for the example regex program, the steps outlined here are enough. However, I started a project using GIL and immediately ran into more problems.

There are two errors that need to be overridden with preprocessor definitions. “wcstombs may be unsafe”, and problems with std::uninitialized_copy and std::copy, somewhere in the boost libraries. These are solved by adding _CRT_SECURE_NO_WARNINGS and _SCL_SECURE_NO_WARNINGS to preprocessor definitions as the error output suggests.

2018-11-11 11_49_27-vs-boost-built-starter Property Pages
Add preprocessor definitions to override compiler errors occurring in boost

The last problem is an unexpected end of file error. This is solved by turning off using precompiled headers in the project properties.

2018-11-11 11_50_09-vs-boost-built-starter Property Pages
Turn off using precompiled headers


You can download the Nuget package for boost, but it also needs to be built in order to access the non header-only classes.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s