gpt4 book ai didi

c++ - 如何在 MSVS 中为 Windows XP 编译 C++ 应用程序?

转载 作者:行者123 更新时间:2023-12-05 01:55:21 25 4
gpt4 key购买 nike

当我读到this article , 下载最新的 MSVS 2022 就足够了然后安装工具集 C++ Windows XP Support for VS 2017 (v141) tools [Deprecated]

之后,我在 Visual Studio 的项目属性中设置了这个工具集。根据链接文章,编译支持 XP 的 C++ 应用程序就足够了。

但是在创建我的 .exe 文件后,如果我在 XP 64 位 SP2 上运行它,它会显示错误,即 KERNEL32 中找不到 CompareStringEx 函数.DLL.

因此看来仅使用此工具集是不够的。还需要其他东西。

在其他一些地方,我看到还需要在编译时添加 define /D_US​​ING_V110_SDK71_,在链接时添加选项 /SUBSYSTEM:CONSOLE,5.01。在我的项目属性中,我也尝试添加这两个选项,但 CompareStringEx 仍然在最终应用程序的导入表中。

作为suggested @BenVoigt,我确实定义了 /DWINVER=0x0502/D_WIN32_WINNT=0x0502。还将 C++ 标准设置为 /std:c++14(我会设置 C++11,但此 MSVS 版本至少允许设置 C++14)。仍然有一些非 XP 符号保留在最终的 EXE 中,例如 InitializeSRWLock这可能被 C++11 的 std::mutex 使用在我的代码中。

有人知道编译完全兼容 XP 的应用程序所需的一切吗?

更新。通过执行上述操作以及将 C++ CRT 运行时设置为 Multi Threaded DLL,即使用 CRT 的动态 DLL 链接,我设法构建了有效的 XP 应用程序。也为 suggested通过@ChuckWalbourn(向下 x86x64 redists),我下载了旧版本的 msvcp140.dll

但对于我的项目来说,拥有静态链接的运行时 (C++ CRT) 非常重要,即在项目属性的运行时字段中使用 Multi Threaded 值。只有当它真的不可能时,我才会使用 DLL CRT。在此之前,欢迎使用有关如何静态链接 CRT 的解决方案,当然可以生成与 XP 兼容的 EXE。

最佳答案

TL;DR 对于 Window XP VC++ REDIST 支持,安装 https://aka.ms/vs/15/release/VC_redist.x86.exe在您的 Windows XP 系统上

-或-

如果您正在执行“并行应用程序本地部署”,则使用来自 C:\Program Files\Microsoft Visual Studio\2022\<edition>\VC\Redist\MSVC\14.16.27012\x86\Microsoft.VC141.CRT 的 DLL。 .

If you want the latest bug fixes to the CRT, you can also download the REDIST for VS 2019 (16.7) per the link on Microsoft Docs.

对于 Windows XP 目标,您使用 v141_xp Visual Studio(VS 2017、VS 2019 或 VS 2022)安装的平台工具集是最新的 VS 2017 (v141) C++ 编译器,使用随附的 Windows 7.1A SDK。

确保您已安装(对于 VS 2022)以下各个组件,因为您使用的是 MFC:

  • Microsoft.VisualStudio.Component.WinXP : C++ Windows XP 支持 VS 2017 (v141) 工具 [已弃用]
  • Microsoft.VisualStudio.Component.VC.v141.x86.x64 : MSVC v141 - VS 2017 C++ x64/x86 构建工具 (v14.16)
  • Microsoft.VisualStudio.Component.VC.v141.MFC : 用于 v141 构建工具(x86 和 x64)的 C++ MFC

If you are doing DirectX development, be sure to read this blog post as well for various implications of using the Windows 7.1A SDK.

要部署到 Windows XP,您可以安装最新的 VS 2017 Visual C++ REDIST 或使用 VS 2019 Visual C++ 到 VS 2019 (16.7)。此后,REDIST DLL 本身与 Windows XP 不兼容

在安装了 VS 2022 的开发系统上,您将拥有一组更新的 Visual C++ REDIST 文件,这些文件是 binary compatible用你的v141_xp Platform Toolset 构建了 EXE,但那些 VC++ REDIST DLL 与 Windows XP 兼容。

IOW: If you look at a dumpbin /imports of the 14.30 (v143 version), 14.29 (v142 latest version), and/or 14.16 (v141 latest version ) copies of msvcp140.dll you will see different imports. The msvcp140.dll sitting in your C:\windows\SysWOW64 folder is going to be the 14.30 version.

关于c++ - 如何在 MSVS 中为 Windows XP 编译 C++ 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70263892/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com