How to use Boost 1.64 in Visual Studio 2017

By , last updated May 19, 2017

After installing Boost 1.64 or any of the previous versions you need to know to use it in VS2017. Remember, only Boost 1.64 and up works with Visual Studio 2017.

As for any of the previous versions of Boost (1.63 and down) the best way of using Boost with Visual Studio is to use property sheets.

<?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_64_0\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    </ClCompile>
    <Link>
      <AdditionalLibraryDirectories>$(PropSheetPath)boost_1_64_0\stage\$(Platform)\lib\</AdditionalLibraryDirectories>
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup />
</Project>

Save the property sheet in a file called boost_current.props. Don’t save the version of boost in the filename. By using a generic name for the property sheet, it’s easier to edit the property sheet itself for the next version of boost.

Another thing to remember. In the recent versions of Visual Studio, the default platform for 32-bit code is x86, not Win32. If you are using x86 as the platform for 32-bit code, then the libraries must be in stage/x86. The build script can be edited so this happens automatically.

Add an existing property sheet to VS2017

Open the property manager.

Add existing property sheet (the one you saved in the previous step).

Verify the property sheet is added for all configurations.

Use the comment section if there are any questions.

Comments

  1. Mark May 19, 2017 Leave a Reply

    Hi, installed Boost and VS2017 (community) on Win10 as explained here.
    I have a problem with Boost.Test. When I compile example of and run it in console, the program wait for pressing any key and not produces output. I’ve tried install precompiled binaries or compile it as explained above. Program return non zero error code, but no output. What I did wrong?

    • Kent Fagerjord May 19, 2017 Leave a Reply

      Hi Mark,

      I made a new Empty Project and tried the sample you linked, and it builds and runs fine. I have Visual Studio 2017 Professional though, not Community.

      I get this output:

      Running 1 test case...
      boost-test.cpp(8): error: in "first_test": check i == 2 has failed
      [1 != 2]
      Press any key to continue . . .
      

      With this code:

      #define BOOST_TEST_MODULE My Test
      #include <boost/test/included/unit_test.hpp>
      
      BOOST_AUTO_TEST_CASE(first_test)
      {
        int i = 1;
        BOOST_TEST(i);
        BOOST_TEST(i == 2);
      
        system("pause");
      }

      Try placing breakpoints in the test project to see if the code is actually run.

      • Mark May 19, 2017 Leave a Reply

        @Kent Fagerjord I’ve open windows cmd and run compiled example.exe. It waits for input, but outputs nothing.
        Microsoft Windows [Version 10.0.14393] (c) 2016 Microsoft Corporation. All rights reserved.
        C:\Users\Mark\Documents\Visual Studio 2017\Projects\example\example>example
        s
        C:\Users\Mark\Documents\Visual Studio 2017\Projects\example\example >

      • Mark May 19, 2017 Leave a Reply

        Ok, sorry, the problem solved by adding “system(“pause”)”.

Leave a Reply


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*