我在我的电脑上安装了Visual Studio 2017社区版。最近我安装了Qt5.10.1。我从一个示例.pro文件生成了一个VS项目:
qmake -tp vc cube.pro
但是,当我打开这个VS项目并构建它时,我得到错误:
找不到Windows SDK版本8.1。安装所需版本的Windows SDK或在项目属性页中更改SDK版本,或右键单击解决方案并选择“重新定位解决方案”。
如何为qmake指定Windows SDK 10.0而不是8.1的所有目标,以便每次使用qmake生成VS项目时都不需要手动重新定位?
您无法从qmake
中选择Windows SDK版本。 qmake
希望在运行之前正确设置环境。
如果直接使用命令行,您将看到以下消息: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
来自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
如果你使用Qt Creator,那你就不走运了。 Qt Creator只检测已安装的MSVC工具链,但没有提供任何方法来向vcvarsall.bat
调用添加选项或手动添加MSVC工具链。