“目标平台版本"对于 VS C++ 项目意味着什么? [英] What does the `Target Platform Version` mean for a VS C++ project?

查看:166
本文介绍了“目标平台版本"对于 VS C++ 项目意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,在 C++ 项目中:

As I understand it, in a C++ project:

  • 项目属性 =>配置属性 =>一般=>平台工具集
    • 告诉编译器针对哪个 SDK 进行物理编译.
    • 例如:v140 将告诉 Visual Studio 2015 使用最新最好的 v8.1 Windows SDK
    • 根据底层操作系统的不同,SDK 函数可以具有不同的 OS-to-OS 函数签名.
    • SDK 应该向后兼容.1
    • 前面提到的宏使您能够指定要针对哪个版本的函数进行编译.

    如果我使用以下设置编译我的应用程序:

    If I compile my application with the following setup:

    • 项目属性 =>配置属性 =>一般=>平台工具集
      • 设置为:v140_xp(Visual Studio 2015 - Windows XP)
      • 设置告诉编译器使用 7.1 SDK,这是有道理的.
      • project properties => configuration properties => General => Platform Toolset
        • set to: v140_xp (Visual Studio 2015 - Windows XP)
        • Setting tells compiler to use the 7.1 SDK, which makes sense.
        • #include
        • #define _WIN32_WINNT 0x0501
        • #define WINVER 0x0501
        • #define NTDDI_VERSION 0x05010000
        • #include
        • 宏告诉编译器使用哪个函数签名,这是有道理的.

        据我所知,目标平台版本似乎可以替代_WIN32_WINNTWINVERNTDDI_VERSION 宏.奇怪的是,通过上述配置,您可以将 Target Platform Version 设置为 199... 而编译器不会生成任何错误或警告.

        From what I can tell, it looks like Target Platform Version is an suposed to be an alternative to the _WIN32_WINNT, WINVER, and NTDDI_VERSION macros. The weird thing is, with the above configuration you can set the Target Platform Version to 1 or 99... and the compiler doesn't generate any errors or warnings.

        这让我想知道:目标平台版本是什么?

        This this leaves me wondering: What is the Target Platform Version for?

        • 编译器:Visual Studio 2015
        • 2016/09/21:根据 Hans 的评论,宏已更新为参考 Windows XP.

        推荐答案

        在 Visual Studio 2015 中,目标平台版本 字段只是设置要使用的 Windows SDK 的版本.请参阅这篇 MSDN 文章以供参考.在 Visual Studio 2019 中,此字段已重命名为 Windows SDK 版本.您仍然需要设置_WIN32_WINNTWINVERNTDDI_VERSION 宏,以及平台工具集字段.它们共同决定了您的应用可以运行的 Windows 版本.

        In Visual Studio 2015 the Target Platform Version field just sets the version of the Windows SDK to use. See this MSDN article for reference. In Visual Studio 2019, this field has been renamed Windows SDK Version. You still need to set _WIN32_WINNT, WINVER, and NTDDI_VERSION macros, as well as the Platform Toolset field. Taken together they determine the versions of Windows your app can run on.

        如果您的应用程序需要在 Windows XP 上运行,则必须选择以 _xp 结尾的平台工具集,选择较旧的 Windows SDK 版本(您需要 7.1A、但选择 7.0 或 8.1 应该可行;见下文),并相应地设置 _WIN32_WINNTWINVERNTDDI_VERSION 宏.请参阅此堆栈溢出帖子 有关设置这些宏并通过 targetver.h 包含相关 SDK 标头的提示.

        If your applications need to run on Windows XP, you have to pick a Platform Toolset ending in _xp, select an older Windows SDK Version (you need 7.1A, but picking 7.0 or 8.1 should work; see below), and set _WIN32_WINNT, WINVER, and NTDDI_VERSION macros accordingly. See this Stack Overflow posting for tips on setting these macros and including related SDK headers via targetver.h.

        如果使用 _xp 平台工具集从命令提示符构建,请参阅此堆栈溢出帖子,了解有关设置 /SUBSYSTEM 链接器选项,用于定义 _USING_V110_SDK71_.

        If building from a Command Prompt with an _xp platform toolset see this Stack Overflow posting for tips on setting the /SUBSYSTEM linker option and for defining _USING_V110_SDK71_.

        Windows SDK 向后兼容,但我还没有找到明确的参考,其中列出了使用给定版本的 Windows SDK 构建时可以定​​位的最旧版本的 Windows.每个 SDK 都列出了系统要求",但这些列出了使用 SDK 进行开发所需的最低 Windows 版本,而不是使用该 SDK 构建的可执行文件可以针对的最低 Windows 版本.我所知道的最好的参考是每个较新的 Windows SDK 中的 sdkddkver.h 标头.在此标题中是 _WIN32_WINNT 版本常量 的列表.例如,在 Windows 7.1A SDK 中,sdkddkver.h_WIN32_WINNT_NT4 定义为支持的最早的 Windows 平台(但我不知道这是否是确定的).

        Windows SDKs are backward-compatible, but I haven't yet found a clear reference which lists the oldest version of Windows you can target when building with a given version of the Windows SDK. Each SDK lists "System Requirements", but these list the minimum version of Windows needed to develop with the SDK, not the minimum version of Windows that executables built with that SDK can target. The best reference I know of is the sdkddkver.h header in each of the newer Windows SDKs. Within this header are a list of _WIN32_WINNT version constants. For example, in the Windows 7.1A SDK, sdkddkver.h defines _WIN32_WINNT_NT4 as the oldest supported Windows platform (but I do not know if this is definitive).

        本答案的其余部分是关于使用 Visual Studio 2019 定位本机 VC++ 应用程序的说明.这些说明也可能适用于较旧的 Visual Studio 版本.

        The rest of this answer are notes regarding targeting for native VC++ apps using Visual Studio 2019. These notes may apply to older Visual Studio versions as well.

        在 Visual Studio 2019 中,选择以 _xp 结尾的平台工具集有一定的怪癖.对于 v120_xp,Windows SDK 版本 字段是隐藏的,但继承的 VC++ 目录 将显示指定了 Windows SDK 7.1A 目录.对于 v140_xp 和 v141_xp 平台工具集,您可以选择 Windows SDK 7.0 或 8.1(对于任一版本,继承的 VC++ 目录 将显示指定了 Windows SDK 7.1A 目录).

        In Visual Studio 2019, selecting a Platform Toolset which ends in _xp has certain quirks. For v120_xp, the Windows SDK Version field is hidden, but the inherited VC++ Directories will show that the Windows SDK 7.1A directory is specified. For v140_xp and v141_xp platform toolsets, you can pick Windows SDK 7.0 or 8.1 (for either, the inherited VC++ Directories will show that the Windows SDK 7.1A directory is specified).

        我不确定在 Visual Studio 2019 中使用 平台工具集 v140_xp 或 v141_xp 时指定 Windows SDK 版本 7.0 或 8.1 之间有什么区别 - 如果有的话.

        I am not sure what the difference is - if any - between specifying Windows SDK Version 7.0 or 8.1 when using Platform Toolset v140_xp or v141_xp in Visual Studio 2019.

        在 Visual Studio 2019 中,为 Windows 桌面应用设置本机 C++ 项目属性时,根据您选择的平台工具集,只读目标平台字段可能更改为Windows 10".但这并不意味着您的 Win32 桌面应用程序将构建为通用 Windows 平台应用程序.根据 平台工具集Windows SDK 版本_WIN32_WINNTWINVER 的值,它仍然适用于旧版本的 WindowsNTDDI_VERSION 宏.

        In Visual Studio 2019, when setting native C++ project properties for a Windows Desktop app, depending on the Platform Toolset you select, the read-only Target Platform field may change to "Windows 10". But this DOES NOT mean your Win32 desktop app will be built as a Universal Windows Platform app. It will still work on older versions of Windows depending on the Platform Toolset, Windows SDK Version and the values for the _WIN32_WINNT, WINVER, and NTDDI_VERSION macros.

        Microsoft 可以更新 VS2019,以便在为 Win32/桌面项目设置属性时,目标平台 字段值将仅显示Windows",而不管所选的平台工具集 或 <强>Windows SDK 版本.

        Microsoft could update VS2019 so the Target Platform field value would show just "Windows" when setting properties for Win32/desktop projects, regardless of the selected Platform Toolset or Windows SDK Version.

        这篇关于“目标平台版本"对于 VS C++ 项目意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆