c++ - 如何在 Microsoft Visual Studio C++ 中以 Windows XP 为目标

标签 c++ windows visual-c++ visual-studio-2015

<分区>

我在 Windows 8.1 上使用 Microsoft Visual Studio 2015。我想编译一个针对 Windows XP 的程序。我已经在谷歌和其他类似问题上查找过,但没有帮助。在解决方案设置中,目标平台工具集设置为Windows XP,但目标平台版本中没有Windows XP的选项。 我读过https://msdn.microsoft.com/en-us/library/windows/desktop/aa383745(v=vs.85).aspx (使用 Windows header )并将这些行添加到我的程序中:

#define WINVER _WIN32_WINNT_WINXP
#define _WIN32_WINNT _WIN32_WINNT_WINXP
#define NTDDI_VERSION NTDDI_WINXP

但是还是不行。它说找不到“MSVCP140.dll”。在我得到这个dll之后,它开始提示找不到“VC140.dll”。之后是“ucrtbased.dll”,最后是“api-ms-win-core-string-11-1-0.dll”,我的 Windows 8.1 计算机中甚至没有它。该程序可以在 Windows 8.1 上运行,但不能在 Windows XP 上运行。 如何使程序在 Windows XP 上运行?

最佳答案

为了使用 VS 2015(或 VS 2012/VS 2013)构建与 Windows XP 兼容的 EXE,您必须使用 v140_xp 平台工具集而不是默认的 v140平台工具集。

UPDATE: Note that VS 2017 includes support for Windows XP via v141_xp. For VS 2019, this feature is no longer being updated but you can still install the v141_xp toolset to use with the VS 2019 IDE.

查看您的项目属性,常规页面:

Property Page

这是因为默认的 Platform Toolset 使用 Windows 8.1 SDK(或者您可以选择加入 Windows 10 SDK),并且它只支持为 Windows Vista 或更高版本构建应用程序。选择 v140_xp 平台工具集时,您使用的是 Windows 7.1 SDK 版本,它是支持面向 Windows XP 或 Windows Server 2003 的最后一个版本。

Note that Visual Studio can target Windows XP Service Pack 3 or Windows Server 2003 Service Pack 2. The C/C++ Runtime is not compatible with older versions of Windows.

如果您在应用程序中使用 DirectX,这会产生一些深远的影响,因为 Windows 7.1 SDK 和 Windows 8 SDK 之间发生了很多变化。参见 this post了解详情。

对于 VS 2015,您还需要在自定义安装选项中或通过程序和功能/Microsoft Visual Studio 2015/更改.../修改选择 Windows XP 支持:

Modify

关于c++ - 如何在 Microsoft Visual Studio C++ 中以 Windows XP 为目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35664861/

相关文章:

c++ - 为什么是这个结果?

c++ - 如何使用scons构建cpp文件: each file with an executable?

windows - 从 SVN 命令行提取文件的修订号

c++ - 从 Linux 到 Windows 交叉编译 C++ 应用程序的手册?

c++ - 线参数的大小

c++ - 如何有效地将 float 别名为命名成员和数组元素?

c++ - 将 ISO8601 字符串转换为自纪元以来的毫秒数

python - 在 Windows 上使用 python 自动 NTLM

c# - 如何将 C++ 对象传递给 C# 类库

c++ - 什么可能导致此链接器错误?