c++windowsvisual-studiovisual-studio-2019

How can I target Windows 8 (not 8.1) with Visual Studio 2019?


I have created a simple C++ console application for Windows in Visual Studio 2019 and I want it to be able to run on Windows 8 (not 8.1) machines.

I have downloaded and installed the Windows 8 SDK from Microsoft's Windows SDK Archive. I can see it is clearly installed alongside the 8.1 and 10 SDKs:

enter image description here

Now when I go to my project properties in Visual Studio, I don't have the option to select the Windows 8 SDK:

enter image description here

I tried to manually enter "8.0" in the Windows SDK version and then point everything to the Windows 8 SDK directories:

enter image description here

But when compiling I get:

Error (active)  E1696   cannot open source file "stddef.h"
Error (active)  E1696   cannot open source file "stdio.h"
Error (active)  E1696   cannot open source file "math.h"
(...lots of similar errors...)
Error   MSB8036 The Windows SDK version 8.0 was not found. Install the required version of Windows SDK or change the SDK version in the project property pages or by right-clicking the solution and selecting "Retarget solution".

Solution

  • You don't need to install old Windows SDKs. It's good enough to have the latest one installed that supports targets since Windows 7.

    Instead of selecting a Windows SDK Version, you should specify the target platform with macros in C/C++ -> Preprocessor:

    WINVER=0x0602
    _WIN32_WINNT=0x0602
    

    When you use the Windows SDK, you can specify which versions of Windows your code can run on. The preprocessor macros WINVER and _WIN32_WINNT specify the minimum operating system version your code supports. Visual Studio and the Microsoft C++ compiler support targeting Windows 7 SP1 and later.