如何指定 qmake 应针对哪个 Windows SDK 版本?

And*_*ndy 4 qt qmake

我的 PC 上安装了 Visual Studio 2017 社区版。最近我安装了Qt5.10.1。我从示例 .pro 文件之一生成了一个 VS 项目:

qmake -tp vc cube.pro
Run Code Online (Sandbox Code Playgroud)

但是,当我打开此 VS 项目并构建它时,出现错误:

未找到 Windows SDK 8.1 版。安装所需版本的 Windows SDK 或更改项目属性页中的 SDK 版本,或通过右键单击解决方案并选择“重定向解决方案”。

我如何一次性指定 qmake 应针对 Windows SDK 10.0 而不是 8.1,以便每次使用 qmake 生成 VS 项目时都不必手动重新定位?

Ben*_*n T 7

您不能从 中选择 Windows SDK 版本qmakeqmake期望在运行之前正确设置环境。

如果直接使用命令行,您将看到以下消息:Remember to call vcvarsall.bat to complete environment setup!. 这意味着您必须使用正确的选项运行 vcvarsall.bat以设置 MSVC 工具链,包括您选择的 Windows SDK 版本。

一些例子:

# MSVC 2017 for 64 bit 
vcvarsall.bat amd64
# MSVC 2017 for 64 bit using Windows 8.1 SDK
vcvarsall.bat amd64 8.1
# MSVC 2017 for 64 bit using Windows 10 SDK version 10.0.10240.0
vcvarsall.bat amd64 10.0.10240.0
# MSVC 2015 (installed with 2017 installer) for 64 bit using Windows 10 SDK version 10.0.10240.0
vcvarsall.bat amd64 10.0.10240.0 -vcvars_ver=14.0
Run Code Online (Sandbox Code Playgroud)

以及来自vcvarsall.bat以下方面的帮助信息:

Syntax:
    vcvarsall.bat [arch] [platform_type] [winsdk_version] [-vcvars_ver=vc_version]
where :
    [arch]: x86 | amd64 | x86_amd64 | x86_arm | x86_arm64 | amd64_x86 | amd64_arm | amd64_arm64
    [platform_type]: {empty} | store | uwp
    [winsdk_version] : full Windows 10 SDK number (e.g. 10.0.10240.0) or "8.1" to use the Windows 8.1 SDK.
    [vc_version] : {none} for default VS 2017 VC++ compiler toolset |
                   "14.0" for VC++ 2015 Compiler Toolset |
                   "14.1x" for the latest 14.1x.yyyyy toolset installed (e.g. "14.11") |
                   "14.1x.yyyyy" for a specific full version number (e.g. 14.11.25503)

The store parameter sets environment variables to support Universal Windows Platform application
development and is an alias for 'uwp'.

For example:
    vcvarsall.bat x86_amd64
    vcvarsall.bat x86_amd64 10.0.10240.0
    vcvarsall.bat x86_arm uwp 10.0.10240.0
    vcvarsall.bat x86_arm onecore 10.0.10240.0 -vcvars_ver=14.0
    vcvarsall.bat x64 8.1
    vcvarsall.bat x64 store 8.1
Run Code Online (Sandbox Code Playgroud)

如果您使用 Qt Creator,那么您就不走运了。Qt Creator 仅检测已安装的 MSVC 工具链,但不提供任何向vcvarsall.bat调用添加选项或手动添加 MSVC 工具链的方法。