如何在Visual Studio 2017中编译Windows XP的代码

How to compile code for Windows XP in Visual Studio 2017

本文关键字:Windows 编译 XP 代码 2017 Visual Studio      更新时间:2023-10-16

我试图在Windows 10上的Visual Studio 2017中为Windows XP编译一个基本的hello world程序。但它给出了一些错误,如图像所示。

我已经尝试了其他Stack Overflow帖子中提到的关于这个问题的步骤,并更改了平台工具"Visual Studio 2017 - Windows XP(v141_xp("。

#include<iostream>
using namespace std;
int main() {
cout << "Hello worldn";
}
1>------ Build started: Project: WindowsProject1, Configuration: Debug Win32 ------
1>C:Program Files (x86)Microsoft Visual Studio2017CommunityCommon7IDEVCVCTargetsPlatformsWin32PlatformToolsetsv141_xpToolset.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 sdkswindowsv7.1aincludeobjbase.h(239): error C2760: syntax error: unexpected token 'identifier', expected 'type specifier'
1>c:program files (x86)microsoft sdkswindowsv7.1aincludegdiplusheaders.h(891): error C4596: 'EmfToWmfBits': illegal qualified name in member declaration
1>c:program files (x86)microsoft sdkswindowsv7.1aincludegdiplusstringformat.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 ==========

您在这里遇到的是XP兼容SDK头文件中的问题。这个问题实际上相当晦涩难懂,但幸运的是,相对容易处理:你只需要"放松"编译器使用的一致性检查的严格性......

为此,请在">解决方案资源管理器"中右键单击你的项目,然后选择"属性"。在调用的属性页上,选择"C/C++"选项卡,然后选择"语言"子选项卡。在随后显示的页面中,确保选择"一致性模式"到">"。这应该可以解决问题。

请随时要求进一步澄清和/或解释。

您没有说您开始使用什么模板,但我怀疑您启用了一致性模式 (/permissive-(。转到"项目->属性"-> C/C++ -> 语言,并将"一致性模式"设置为"否"。

用于支持Windows XP的旧Windows 7.1a SDK从未更新以符合/permissive-