Troubles with Windows SDK

I recently installed a fresh copy of Visual Studio 2017 on a new machine and went on to build several projects some of them being VC++. The trouble was that I immediately run into a problem (actually the first problem was that MFC & ATL were missing because I forgot to check that in the list of Individual components so I had to install them separately). The problem was an error with a missing new.h header:

1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.15.26726\atlmfc\include\afx.h(62): fatal error C1083: Cannot open include file: ‘new.h’: No such file or directory

That happens on compiling the following piece of code in afx.h:

#ifndef _INC_NEW
	#include <new.h>
#endif

Searching for the new.h header releaved two locations:

c:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\SDK\ScopeCppSDK\SDK\include\ucrt\new.h
c:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\ucrt\new.h

But looking at the location of the include directories in Visual C++ (from the expansion of $(VC_IncludePath);$(WindowsSDK_IncludePath);) I’ve seen only these:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.15.26726\include
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.15.26726\atlmfc\include
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\VS\include
C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\VS\UnitTest\include
C:\Program Files (x86)\Windows Kits\8.1\Include\um
C:\Program Files (x86)\Windows Kits\8.1\Include\shared
C:\Program Files (x86)\Windows Kits\8.1\Include\winrt
C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\Include\um

None of the actual locations where new.h was present were in this list. That was because I had chosen to install version 10.0.17134.0 of the Windows SDK and no other version. However, my Visual C++ projects were targeting Windows SDK 8.1. It turns out that is in hard-coded in MSBuild that 10.0.10240.0 is used when targeting 8.1. Here is the relevant excerpt from c:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\VC\VCTargets\Microsoft.Cpp.Common.props

<!-- 10.0.10240.0 is the hardcoded checked-in version of uCRT that we use in case we target 8.1 SDK -->
<TargetUniversalCRTVersion Condition="'$(TargetUniversalCRTVersion)' == ''  and ('$(TargetPlatformVersion)' == '8.1' or '$(DefineWindowsSDK_71A)' == 'true')">10.0.10240.0</TargetUniversalCRTVersion>
<UniversalCRT_PropsPath Condition="'$(UniversalCRT_PropsPath)' == ''">$(UniversalCRTSdkDir)\DesignTime\CommonConfiguration\Neutral\ucrt.props</UniversalCRT_PropsPath>

To solve this there are three possible solution:

  1. Install the required 10.0.17134.0 Windows SDK. To do so, you need to run the Visual Studio Installer, select Individual Components and check it in the list.

    Mind that this SDK requires an additional 3GB of disk space.

  2. Change the targe version from 8.1 to 10.0.17134.0 or whatever else you have installed.

    If you plan to do this and you work in a team with other developers and have dedicated build machines, etc. you need to coordinate so that everybody has the target version of the SDK installed, otherwise the build will run on your machine but not on others.

  3. Manually alter the MSBuild user property files C:\Users\{user}\AppData\Local\Microsoft\MSBuild\v4.0\Microsoft.Cpp.<target>.user.props (where <target> is Win32, x64 and Arm) to overwrite the defaults. These files are initially empty and should look like this:
    <?xml version="1.0" encoding="utf-8"?> 
    <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <ImportGroup Label="PropertySheets">
      </ImportGroup>
      <PropertyGroup Label="UserMacros" />
      <PropertyGroup />
      <ItemDefinitionGroup />
      <ItemGroup />
    </Project>

    You can replace the empty PropertyGroup item with the following (this example is for x86, but you need to do the same with the appropriate paths in all the files):

    <PropertyGroup>
       <IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);c:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\ucrt\;</IncludePath>
       <LibraryPath>$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);c:\Program Files (x86)\Windows Kits\10\Lib\10.0.17134.0\ucrt\x86\;</ExecutablePath>
    </PropertyGroup>

5 Replies to “Troubles with Windows SDK”

  1. Hi Marius, long time, hope you are well. This helped me a lot, thank you. There is a typo at the end of line 3, it ends with “” which should be . The compiler pointed this out.

  2. There is a mistake in #1. Not “Install the required 10.0.17134.0 Windows SDK”, but “Install the required 10.0.10240.0 Windows SDK”.
    10.0.10240.0 is required for Win8.1, it is missed and it should be isntalled. Screenshot is corrent, just the bug in the description

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.