我安装了 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)中的以下设置:
然后我得到以下输出:
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
如果我打开生成的解决方案,它会 - 正如预期的那样 - 询问我:
平台工具集映射
来自 Marco Foco: Microsoft Visual C++ version Map :
如果那不行...
首先请检查二进制输出目录中的CMakeError.log
。该错误应该让您了解问题所在。
如果这没有帮助,您可以尝试几种方法(除了重新安装 VS,我认为这不会解决问题):
- 其中一个 Windows SDK 未完全/正确安装;从 Microsoft 的网站重新安装
- 尝试赋予
cmake-gui
管理权限 - 检查您的 PATH 环境中是否有带有 GCC 编译器的 GNU 工具链。
引用资料
关于c++ - CMake:如何在安装了 VS2017 的情况下指定 VS2015.3 工具集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47154454/