6

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 ==========

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
0xVikas
  • 108
  • 1
  • 9

2 Answers2

11

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.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
  • But now I am facing another problem, After successful compilation, when I run the program on windows xp, Its showing me that some DLL files are missing. Can you plz help me fix this ? – 0xVikas Oct 16 '19 at 17:29
  • @0xVikas You'll almost certainly need to install the relevant "VC Redistributable" package on the target machine(s). There's a recent discussion of this here: https://stackoverflow.com/questions/58336827/how-to-run-a-c-program-i-wrote-on-another-computer/58336900#58336900 – Adrian Mole Oct 16 '19 at 17:32
  • 2
    Thanks ! I fixed it by changing "code generation -> Runtime library" to Multi Threaded Debug to statically include all the DLLs. – 0xVikas Oct 16 '19 at 17:38
3

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-.

Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81