使用cmake+qt5+vs2017生成解决方案报错:
D:\build\test\Reader_qt5\build2017>cmake ../ -G "Visual Studio 15 2017"
CMake Error at CMakeLists.txt:14 (project):
Failed to run MSBuild command:
d:/Program Files (x86)/Microsoft Visual Studio/2017/Community/MSBuild/15.0/Bin/MSBuild.exe
to get the value of VCTargetsPath:
用于 .NET Framework 的 Microsoft (R) 生成引擎版本 15.9.21+g9802d43bc3
版权所有(C) Microsoft Corporation。保留所有权利。
生成启动时间为 2024/12/17 10:17:21。
节点 1 上的项目“D:\build\test\Reader_qt5\build2017\CMakeFiles\3.17.1\VCTargetsPath.vcxproj”(默认目标)。
d:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.Cpp.WindowsSDK.targets(46,5): error MSB8036: 找不到 Windows SDK 版本8.1。请安装所需的版本的 Windows SDK 或者在项目属性页中或通过右键单击解决方案并选择“重定解决方案目标”来更改 SDK 版本。 [D:\build\test\Reader_qt5\build2017\CMakeFiles\3.17.1\VCTargetsPath.vcxproj]
已完成生成项目“D:\build\test\Reader_qt5\build2017\CMakeFiles\3.17.1\VCTargetsPath.vcxproj”(默认目标)的操作 - 失败。
生成失败。
解决:
适用情况
使用VS2017+Qt5新建Qt程序时,Windows SDK版本默认被设置为8.1。
而VS2017安装的Windows SDK版本为10.0.16299.0。
每次都需要修改SDK版本才能进行编译。如果不修改则会报错。
自己动手修改默认Windows SDK版本为10.0.16299.0
找到Qt VS Tools安装目录 C:\Users\***\AppData\Local\Microsoft\VisualStudio\15.0_40f57358\Extensions
这里是Extensions
的安装目录,文件夹内即安装的插件的内容(名字是随机的)。
找到Qt VS Tools的目录
打开chkvpks3.3mz\ProjectTemplates\VC\Qt\1033\gui
,这里就是创建模版存放的位置。找到需要修改的模版,比如我要修改gui。
进入目录,用记事本打开gui.vcxproj
项目文件。
在PropertyGroup
里面添加<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
,保存即可。
再创建的Gui程序的默认Windows SDK版本就是想要的10.0.16299.0了。
参考:https://liuchang0523.github.io/2017/12/%E4%BF%AE%E6%94%B9Qt-VS-Tools%E6%A8%A1%E7%89%88/