c++ - CMake:如何在安装了 VS2017 的情况下指定 VS2015.3 工具集

标签 c++ visual-studio-2015 compilation cmake visual-studio-2017

我安装了 VS2017,同时安装了 VS2017 (v141) 和 VS2015.3 (v140) 工具集。我需要使用 CMake 生成一个解决方案,我希望 CMake 被“愚弄”,就像安装了 VS2015 一样,这样我就可以使用 v140 工具集构建项目。
我知道这个问题可能与以下问题重复: How cmake specify "Platform Toolset" for a Visual Studio 2015 project?
但它提供的解决方案对我没有帮助。
错误信息是:

Selecting Windows SDK version 10.0.14393.0 to target Windows 10.0.15063.
The C compiler identification is unknown
The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:18 (project):
  No CMAKE_C_COMPILER could be found.

我尝试同时安装 VS2017 和 VS2015.3 (IDE),但 VS2015.3 甚至拒绝创建一个简单的控制台程序。
还有其他方法可以使用 v140 工具集生成解决方案吗?
(P.S. 不要告诉我应该先用 v141 工具集生成,然后在 Visual Studio 中修改工具集选项。这会有很大的不同。)

最佳答案

我刚刚运行了一个测试,它适用于 CMake 的 GUI(版本 3.10.0 RC4)中的以下设置:

enter image description here

然后我得到以下输出:

The CXX compiler identification is MSVC 19.0.24215.1
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
Configuring done
Generating done

如果我打开生成的解决方案,它会 - 正如预期的那样 - 询问我:

enter image description here

平台工具集映射

来自 Marco Foco: Microsoft Visual C++ version Map :

enter image description here

如果那不行...

首先请检查二进制输出目录中的CMakeError.log。该错误应该让您了解问题所在。

如果这没有帮助,您可以尝试几种方法(除了重新安装 VS,我认为这不会解决问题):

  1. 其中一个 Windows SDK 未完全/正确安装;从 Microsoft 的网站重新安装
  2. 尝试赋予cmake-gui管理权限
  3. 检查您的 PATH 环境中是否有带有 GCC 编译器的 GNU 工具链。

引用资料

关于c++ - CMake:如何在安装了 VS2017 的情况下指定 VS2015.3 工具集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47154454/

相关文章:

c++ - std::bad_alloc 运行时异常

c++ - 从文件中读取选定范围的行并存储到数组中

visual-studio-2015 - VSIX 安装程序 : SignatureDescription could not be created for the signature algorithm supplied

c++ - 从 size_t 到 wchar_t 的转换需要缩小转换

c++ - 无法创建项目,无法识别的命令行选项 libc++ 错误

c - 有没有办法检测,C 文件被直接编译成可执行文件?

java - 如何为64位Linux机器编译Hadoop?

c++ - 双向插入排序错误

c++ - Qt - Q_OBJECT 与#include <QObject>

ios - Visual Studio 2015 RTM Cordova IOS 构建错误 - 找不到模块 'Q'