How to use C++ Boost library in Visual Studio 2013/2015

By , last updated September 30, 2019

This guide shows how to use Boost library with Visual Studio 2013 or 2015. Guide for using Boost with VS2017.

There are a couple ways to use Boost with Visual Studio, here are two ways: Property pages and Property sheets.

Property pages

Make sure Configuration is set to All Configurations and Platform is set to All Platforms. If not, you’ll have different settings for Release/Debug and with Win32/x64.

Add the boost_1_61_0 folder to the Additional Include Directories (boost_1_60_0 folder if you are using Boost 1.60). It’s wise to use a path relative to the solution file or project file. The include directory is $(SolutionDir)boost_1_61_0\.

additional-include-directories

And Additional Include Directories. It’s also wise to have the library directories relative to the solution file or project file. I’m using solution file as reference.

The actual library directory is $(SolutionDir)boost_1_61_0\stage\$(Platform)\lib\ for Boost 1.61 or $(SolutionDir)boost_1_60_0\stage\$(Platform)\lib\ for Boost 1.60.

additional-library-directories

The macro $(Platform) will expand to either Win32 or x64, which are the same directories the binaries are installed to in the first step.

Property sheet

Say if you have multiple projects, which all use Boost. But due to limited disk space, you want to have one installation of Boost, and not per project. This is the easiest way of doing that, without actually installing it anywhere.

Property sheets are project properties not attached to any specific project, but can be added to multiple projects. Open Property Manager (View -> Property Manager).

visual-studio-property-manager

Right-click and Add New Project Property Sheet and save it in the same folder as the boost_1_61_0 directory. Not within the boost directory, but next to it.

The next step requires some manual editing in the property sheet file, to be able to use the path the property sheet file is in.

Add the following section within the <PropertyGroup Label="UserMacros"> section.

<PropSheetPath>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)'))</PropSheetPath>

At this point, you’ll have another macro available, which will point to the directory of the property sheet itself. We’ll use this macro to create a path to the directory containing the boost libraries.

additional-include-directories-property-sheet

Make sure Inherit from parent or project defaults are checked, and press OK to add the path to Additional Include Directories.

additional-include-directories-property-sheet-2

additional-library-directories-property-sheet-2

The values should read:

  • Additional Include Directories: $(PropSheetPath)boost_1_61_0\;%(AdditionalIncludeDirectories)
  • Additional Library Directories: $(PropSheetPath)boost_1_61_0\stage\$(Platform)\lib\

The complete property sheet file should be like this.

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
 <ImportGroup Label="PropertySheets" />
 <PropertyGroup Label="UserMacros">
 <PropSheetPath>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)'))</PropSheetPath>
 </PropertyGroup>
 <PropertyGroup />
 <ItemDefinitionGroup>
 <ClCompile>
 <AdditionalIncludeDirectories>$(PropSheetPath)boost_1_61_0\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
 </ClCompile>
 <Link>
 <AdditionalLibraryDirectories>$(PropSheetPath)boost_1_61_0\stage\$(Platform)\lib\</AdditionalLibraryDirectories>
 </Link>
 </ItemDefinitionGroup>
 <ItemGroup />
</Project>

Using the property sheet in your project

The values in the property sheet will not always be used, even though they are configured correctly.

error-list

It will be very apparent when errors like “Cannot open include file: boost/something/something.hpp” keeps appearing. You must tell your project to use the inherited values by checking 1 box, Inherit from parent or project defaults. This goes for both include directories and library directories.

inherit-from-parent-or-project-defaults

For your project, the values should read:

  • Additional Include Directories: %(AdditionalIncludeDirectories)
  • Additional Library Directories: %(AdditionalLibraryDirectories)

See the difference between Library and Include.

When all is set, you can build many projects from the same boost source files using the same property sheet from all project.

Now it’s time to write some Boost examples.