c++ - CMake 找不到 VS 14 2015 的 MSBuild.exe

标签 c++ cmake visual-studio-2017

我正在使用 Visual Studio 14 2015 win64 中的预编译库构建一个新项目。 因此,当我配置项目 Cmake 时,我选择了此编译器,但出现错误:

CMake Error at CMakeLists.txt:2 (project):
Failed to run MSBuild command:
MSBuild.exe
to get the value of VCTargetsPath:
Specified file is not found

为什么 Cmake 找不到该编译器的位置?

我有 Visual Studio Community 2017,并安装了 Visual Studio 14 2015 win64 的附加组件。我已经可以通过使用 Visual Studio 15 2017 win64 设置我的项目来使我的解决方案正常工作,然后手动更改为 2015。

我应该怎么做才能让 Cmake 直接使用 VS14 2015 编译器完成它?

最佳答案

VS 开发 shell 隐藏在开始菜单中(Visual Studio 2017->Visual studio Tools->VC),有多种可供选择。

然后就可以使用命令行运行cmake -G "Visual Studio 14 2015 Win64"

我不完全确定这是否有效,因为生成器将查找“Visual Studio 14 2015”的注册表项以确定正确的 msbuild 的路径。但您尚未安装它,因为您使用的是 Visual Studio Community 2017,其工作方式完全不同。

因此,当 cmake 无法找到 VS14msbuild 时,它将默认为路径中的任何内容,即 msbuild 适用于 VS 2017

此时您将了解该附加组件是否与 cmake VS14 项目和工具集兼容。

该附加组件可能只是 VS14 工具集。如果是这种情况,您希望生成 VS17 项目并使用 -T 选项来使用 VS14 工具集。

Visual Studio 和 CMake 也将 msbuild 称为构建工具。 -T 选项用于选择平台工具集,即要使用的编译器版本。

关于c++ - CMake 找不到 VS 14 2015 的 MSBuild.exe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54262085/

相关文章:

c++ - 在不膨胀命名空间的情况下在 C++ 中声明枚举的好方法

c++ - CMake 将项目设置为 C++ 20

c++ - 在 Mac OS-X 上编译 C++ 程序时出现 "framework not found"

C++ 链接对象的文件 (G++)

c++ - 如何用 NULL 填充指针数组?

c++ - 如何使用 CMake 包含 NTL

c++ - 在模板中使用 noexcept 运算符

c++ - Visual Studio 2017 msvc vs nvcc __cplusplus 宏不匹配

visual-studio-2017 - 请选择有效的启动项

c++ - 从不同基类的基指针转换为基类(最好没有 dynamic_cast)