Building Boost 1.64 with Visual Studio 2017

By , last updated November 7, 2017

Visual Studio 2017 has been released, and it wasn’t exactly trivial to get previous versions of boost (1.63 and down) to build with it.

There were a multitude of difficulties, but the two main problems are:

  1. find the installation directory of VS2017, and
  2. boost build scripts are strictly tied to versions of compilers.

Unless a boost release doesn’t support a particular version of Visual Studio, it isn’t very easy to build boost with it.

Boost 1.64 was released 20th of April 2017 and can be downloaded from http://www.boost.org/users/history/version_1_64_0.html.

New in Boost 1.64 is a library called Boost.Process. It has been in development since 2006 and provides a cross platform way of spawning child processes and communication through synchronous or asynchronous streams.

Building Boost 1.64 with Visual Studio 2017

For the impatient, scripts are available at Github: https://github.com/Studiofreya/boost-build-scripts.

Boost 1.64 is the first Boost release after Visual Studio 2017 was released 7th of March 2017. This time they haven’t slapped 2017 over 2015. Microsoft have redone the installer, the (internal) location of the tools and it is possible to have multiple versions of Visual Studio 2017 installed, each with their own set of available tools.

  1. Download and extract the Boost archive from http://www.boost.org/users/history/version_1_64_0.html.
  2. Create a file named build_boost_1_64_vs2017.bat in the same folder as boost_1_64_0 with the following contents:
@echo off
rem Directory to boost root
set boost_dir=boost_1_64_0

rem Number of cores to use when building boost
set cores=%NUMBER_OF_PROCESSORS%

rem What toolset to use when building boost.

rem Visual Studio 2012 -> set msvcver=msvc-11.0
rem Visual Studio 2013 -> set msvcver=msvc-12.0
rem Visual Studio 2015 -> set msvcver=msvc-14.0
rem Visual Studio 2017 -> set msvcver=msvc-14.1

set msvcver=msvc-14.1

rem Start building boost
echo Building %boost_dir% with %cores% cores using toolset %msvcver%.

cd %boost_dir%
call bootstrap.bat

rem Most libraries can be static libs
b2 -j%cores% toolset=%msvcver% address-model=64 architecture=x86 link=static threading=multi runtime-link=shared --build-type=minimal stage --stagedir=stage/x64 
b2 -j%cores% toolset=%msvcver% address-model=32 architecture=x86 link=static threading=multi runtime-link=shared --build-type=minimal stage --stagedir=stage/win32
b2 -j%cores% toolset=%msvcver% address-model=64 architecture=x86 link=shared threading=multi runtime-link=shared --build-type=minimal stage --stagedir=stage/x64 
b2 -j%cores% toolset=%msvcver% address-model=32 architecture=x86 link=shared threading=multi runtime-link=shared --build-type=minimal stage --stagedir=stage/win32

pause

This script has been tested with a clean install of Windows 10 and a minimal install of Visual Studio 2017 with C++.

Older versions of Visual Studio

This bat file can be adjusted to build Boost 1.64 with Visual Studio 2012, 2013, 2015 and 2017 by adjusting the msvcver variable.

  • Visual Studio 2012 -> set msvcver=msvc-11.0
  • Visual Studio 2013 -> set msvcver=msvc-12.0
  • Visual Studio 2015 -> set msvcver=msvc-14.0
  • Visual Studio 2017 -> set msvcver=msvc-14.1

Using Boost 1.64 in Visual Studio 2017

Guide on how to use Boost 1.64 in VS2017 or any of the previous versions of Visual Studio.

Use the comment section if there are any questions.

Comments

  1. Jeremy Thorne May 31, 2017 Leave a Reply

    Using the scripts as-is from the repo, it appears to be building the shared versions of the .libs instead of the static versions, even though static is specified. I end up with filenames such as libboost_atomic-vc141-mt-gd-1_64.lib instead of libboost_atomic-vc141-mt-sgd-1_64.lib, and further inspection reveals that it is definitely the shared version, not just incorrect filenames.

  2. Sean Hoffman August 30, 2017 Leave a Reply

    Hi, thanks for the article and the work you did to find this. I tried this with boost 1.65 (changing the version names in the batch script accordingly) and I still see lots of “Unknown compiler version – please run the configure tests and report the results” warnings. Do you see these following your instructions?

  3. MATT September 12, 2017 Leave a Reply

    I am getting error building Boost 1-65-1 for VS 2017 (15.3.3). Any idea why?
    ==========================================================
    My cmd window shows this:
    Building boost_1_65_1 with 8 cores using toolset msvc-14.1.
    Building Boost.Build engine
    Failed to build Boost.Build engine.
    Please consult bootstrap.log for further diagnostics.
    You can try to obtain a prebuilt binary from
    http://sf.net/project/showfiles.php?group_id=7586&package_id=72941
    Also, you can file an issue at http://svn.boost.org
    Please attach bootstrap.log in that case.
    ‘b2’ is not recognized as an internal or external command,
    operable program or batch file.
    ‘b2’ is not recognized as an internal or external command,
    operable program or batch file.
    Press any key to continue . . .
    ===================================================
    My Boost log file shows this….
    **********************************************************************
    ** Visual Studio 2017 Developer Command Prompt v15.0.26730.12
    ** Copyright (c) 2017 Microsoft Corporation
    **********************************************************************
    [vcvarsall.bat] Environment initialized for: ‘x86’
    ###
    ### Using ‘vc141’ toolset.
    ###
    C:\Users\Valued Customer\source>if exist bootstrap rd /S /Q bootstrap
    C:\Users\Valued Customer\source>md bootstrap
    C:\Users\Valued Customer\source>cl /nologo /RTC1 /Zi /MTd /Fobootstrap/ /Fdbootstrap/ -DNT -DYYDEBUG -wd4996 kernel32.lib advapi32.lib user32.lib /Febootstrap\yyacc0 yyacc.c
    yyacc.c
    c1: fatal error C1083: Cannot open source file: ‘yyacc.c’: No such file or directory
    =========================================================

    • Kent Fagerjord September 12, 2017 Leave a Reply

      Hi Matt,

      I’ve seen that error before. Some colleagues had it. I think it boiled down to the VS2017 environment. Try installing the “Windows 10 SDK” component in the VS2017/C++ setup. This applies even if you don’t have Win10 as operating system.

      Kent

  4. MATT September 12, 2017 Leave a Reply

    Thanks. I tried to install Windows 10 SDK and got this. Still, I tried to run the boost install script and got the same error…
    I did google and installed the latest Windows sdk desperately and boost still did not install.
    I am using Windows 7.
    ==========================================================
    Something went wrong with the install.

    You can troubleshoot the package failures by:

    1. Search for solutions using the search URL below for each package failure
    2. Modify your selections for the affected workloads or components and then retry the installation
    3. Remove the product from your machine and then install again

    If the issue has already been reported on the Developer Community, you can find solutions or workarounds there. If the issue has not been reported, we encourage you to create a new issue so that other developers will be able to find solutions or workarounds. You can create a new issue from within the Visual Studio Installer in the upper-right hand corner using the “Provide feedback” button.

    ================================================================================

    Package ‘Win10SDK_Hidden_10.0.10240_2,version=10.0.10240.117’ failed to install.
    Search URL
    https://aka.ms/VSSetupErrorReports?q=PackageId=Win10SDK_Hidden_10.0.10240_2;PackageAction=Install;ReturnCode=1001
    Details
    Command executed: “c:\windows\syswow64\\windowspowershell\v1.0\powershell.exe” -NonInteractive -NoLogo -NoProfile -ExecutionPolicy Bypass -InputFormat None “$ErrorActionPreference=”””Stop”””; $VerbosePreference=”””Continue”””; $CeipSetting=”””on”””; $ScriptPath=”””C:\ProgramData\Microsoft\VisualStudio\Packages\Win10SDK_Hidden_10.0.10240_2,version=10.0.10240.117\WinSdkInstall.ps1″””; $SetupExe=”””sdksetup.exe”””; $SetupLogFolder=”””standalonesdk”””; $PackageId=”””Win10SDK_Hidden_10.0.10240_2″””; $LogFile=”””C:\Users\Valued Customer\AppData\Local\Temp\dd_setup_20170912063350_001_Win10SDK_Hidden_10.0.10240_2.log”””; $SetupParameters=”””/features OptionId.AvrfExternal OptionId.WindowsSoftwareDevelopmentKit OptionId.WindowsSoftwareLogoToolkit /quiet /norestart”””; $PayloadsNotYetDownloaded=1; (gc $ScriptPath | out-string) | Invoke-Expression; if (!$?) { exit 1603 } elseif ($LastExitCode) { exit $LastExitCode }”
    Return code: 1001
    Return code details: Recursion too deep; the stack overflowed.
    Log
    C:\Users\Valued Customer\AppData\Local\Temp\dd_setup_20170912063350_001_Win10SDK_Hidden_10.0.10240_2.log
    Impacted workloads
    Desktop development with C++ (Microsoft.VisualStudio.Workload.NativeDesktop,version=15.0.26606.0)
    Impacted components
    Windows 10 SDK (10.0.10240.0) (Microsoft.VisualStudio.Component.Windows10SDK.10240,version=15.0.26208.0)

  5. MATT September 20, 2017 Leave a Reply

    I finally got it to Build: I usually click the *.bat file and it runs. This time, I had to use “x64 Native Tools Command Prompt for VS 2017” on *.bat file. Shoo! Any idea why cmd.exe worked in the past and now but now it does not? Thanks.

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>

*