How to compile code for Windows XP in Visual Studio 2017

Viewed 2626

I was trying to compile a basic hello world program for Windows XP in Visual Studio 2017 on Windows 10. But it was giving some errors as showing in the image.

I already tried the steps mentioned in other Stack Overflow posts on this question, and changed the Platform tools "Visual Studio 2017 - Windows XP (v141_xp)" .

#include<iostream>
using namespace std;
int main() {
    cout << "Hello world\n";
}
1>------ Build started: Project: WindowsProject1, Configuration: Debug Win32 ------
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Platforms\Win32\PlatformToolsets\v141_xp\Toolset.targets(39,5): warning MSB8051: Support for targeting Windows XP is deprecated and will not be present in future releases of Visual Studio. Please see https://go.microsoft.com/fwlink/?linkid=2023588 for more information.
1>stdafx.cpp
1>c:\program files (x86)\microsoft sdks\windows\v7.1a\include\objbase.h(239): error C2760: syntax error: unexpected token 'identifier', expected 'type specifier'
1>c:\program files (x86)\microsoft sdks\windows\v7.1a\include\gdiplusheaders.h(891): error C4596: 'EmfToWmfBits': illegal qualified name in member declaration
1>c:\program files (x86)\microsoft sdks\windows\v7.1a\include\gdiplusstringformat.h(220): error C4596: 'GetTrimming': illegal qualified name in member declaration
1>Done building project "WindowsProject1.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

2 Answers

What you have encountered here are issues in the header files for the XP-Compatible SDK. The problem is actually quite arcane but, fortunately, relatively easy to deal with: you simply need to 'relax' the strictness of conformity checks the compiler uses...

To do this, right-click on your project in the Solution Explorer and select "Properties." On the invoked property-page, select the "C/C++" tab, and then the "Language" sub-tab. In the page then displayed, make sure you select "Conformance Mode" to "No". That should fix the issues.

Feel free to ask for further clarification and/or explanation.

You didn't say what template you started with, but I suspect that you have Conformance Mode (/permissive-) enabled. Go to Project -> Properties -> C/C++ -> Language and set Conformance Mode to "No".

The old Windows 7.1a SDK used to support Windows XP was never updated to be conformant with /permissive-.

Related