c++ - 如何在 Visual Studio 2017 中为 Windows XP 编译代码

标签 c++ visual-studio visual-c++ visual-studio-2017 windows-xp

我试图在 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 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 ==========

最佳答案

您在这里遇到的是 XP 兼容 SDK 的头文件中的问题。这个问题实际上非常神秘,但幸运的是,它相对容易处理:您只需要“放宽”编译器使用的一致性检查的严格性...

为此,请在解决方案资源管理器 中右键单击您的项目并选择“属性”。在调用的属性页上,选择“C/C++”选项卡,然后选择“语言”子选项卡。在随后显示的页面中,确保将“Conformance Mode”选择为“No”。这应该可以解决问题。

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

关于c++ - 如何在 Visual Studio 2017 中为 Windows XP 编译代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58417992/

相关文章:

c++ - 将两个链表中的特定值相加时出现问题

vb.net - 部署 VB.NET 应用程序的最佳方法是什么?

c# - 无法在 Visual Studio 中键入

c++ - boost 库 vc100

c++ - 新手 - 将 char* 转换为字符串

c++ - 使用静态 openssl 1.1.1a 编译静态 curl

c++ - gsl_histogram : Value being equal to an edge between two bins, 值会分配给哪个bin?

用于应用程序/程序设置的 C++ 类?

c++ - Char 数组转 long 转 char 数组

windows - 视觉小尺寸语言