This guide shows how to use Boost library with Visual Studio 2013 or 2015.
There are a couple ways to use Boost with Visual Studio, here are two ways. Property pages and Property sheets.
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
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.
$(Platform) will expand to either
x64, which are the same directories the binaries are installed to in the first step.
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 (
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.
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.
Inherit from parent or project defaults are checked, and press OK to add the path to
Additional Include Directories.
The values should read:
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>
The values in the property sheet will not always be used, even though they are configured correctly.
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
For your project, the values should read:
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.