我在 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.
查看您的项目属性,常规页面:
这是因为默认的 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 支持: