Visual Studio 2017的CMake生成问题

Visual Studio 2017的CMake生成问题,cmake,Cmake,使用命令行中的cmake,我得到: "== Building Windows-Release ==" -- Building for: Visual Studio 15 2017 -- The C compiler identification is unknown -- The CXX compiler identification is unknown CMake Error at CMakeLists.txt:2 (project): No CMAKE_C_COMPILER could b

使用命令行中的
cmake
,我得到:

"== Building Windows-Release =="
-- Building for: Visual Studio 15 2017
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:2 (project):
No CMAKE_C_COMPILER could be found.



CMake Error at CMakeLists.txt:2 (project):
No CMAKE_CXX_COMPILER could be found.
其中
CMakeError.log
包含:

Compiling the C compiler identification source file "CMakeCCompilerId.c" failed.
Compiler:  
Build flags: 
Id flags:  

The output was:
1
Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 31/12/2018 12:54:05.
Project "C:\myproj\CMakeFiles\3.13.1\CompilerIdC\CompilerIdC.vcxproj" on node 1 (default targets).
PrepareForBuild:
Creating directory "Debug\".
Creating directory "Debug\CompilerIdC.tlog\".
InitializeBuildStatus:
Creating "Debug\CompilerIdC.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
ClCompile:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\CL.exe /c /nologo /W0 /WX- /Od /Oy- /D _MBCS /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"Debug\\" /Fd"Debug\vc140.pdb" /Gd /TC /analyze- /errorReport:queue CMakeCCompilerId.c
CMakeCCompilerId.c
c1 : fatal error C1083: Cannot open source file: 'CMakeCCompilerId.c': No such file or directory [C:\myproj\CMakeFiles\3.13.1\CompilerIdC\CompilerIdC.vcxproj]
Done Building Project "C:\myproj\CMakeFiles\3.13.1\CompilerIdC\CompilerIdC.vcxproj" (default targets) -- FAILED.

Build FAILED.

"C:\myproj\CMakeFiles\3.13.1\CompilerIdC\CompilerIdC.vcxproj" (default target) (1) ->
(ClCompile target) -> 
c1 : fatal error C1083: Cannot open source file: 'CMakeCCompilerId.c': No such file or directory [C:\myproj\CMakeFiles\3.13.1\CompilerIdC\CompilerIdC.vcxproj]

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.43
...

我试图修复Visual Studio的安装,并重新安装CMake,但似乎没有任何效果。这里也看到了类似的线索,但没有任何帮助。

我遇到了与您完全相同的问题。经过很长时间的斗争,我终于找到了解决办法。我不确定这是否是你遇到的同一个问题,但我仍然想写下并重新编码这个奇怪的问题

首先,我还重新安装了cmake,修复了VS,并在其中添加了许多组件,修复了(制动)多路径环境,但所有这些都不起作用,我打赌问题不是因为这些问题

作为两条信息:

  • C编译器标识未知
  • CXX编译器标识未知
它们并不完全意味着cmake没有检测到VS编译器,它只是意味着cmake使用它来构建演示,但失败了。从错误日志中,我甚至可以相信你的VS已经安装成功并且运行良好。唯一的问题是编译器无法打开“cmakccompilerid.c”文件

我不知道是否让您检查.c文件是否确实在项目位置,但它在我的计算机中很好地存在(否则,这意味着cmake无法创建此文件,您可能需要作为管理员打开它) 我很困惑为什么编译器不能读取它,并尝试在VS中直接打开.vcxproj文件并更改许多设置,但仍然会得到相同的错误,如下所示

经过一番尝试后,我将项目移动到桌面并重新打开,然后它就成功了!整个cmake项目也是如此。我对此也感到震惊

经过一些比较和研究,我发现了我的错误原因,我正在使用windows wsl中的git将项目克隆到我的windows文件系统(在wsl中破坏文件权限的风险很小),它在正常情况下运行良好,但作为cmake交叉编译,我猜它可能会使用一些类似linux的方式来操作文件,因此会遇到一些文件权限问题

因此,我的最终解决方案是在cmd中使用git,或者在浏览器中下载整个项目,而不是在wsl中使用git。(确实有点滑稽-,可能会因您的情况而有所不同)


希望这些可以帮助您。

文件
C:\myproj\CMakeFiles\3.13.1\CompilerIdC\cmakccompilerid.C
是否存在?它应该位于
C:\myproj\cmakfiles\3.13.1\CompilerIdC\CompilerIdC.vcxproj
旁边。这是所有项目都会发生还是只有这一个?另外,我通常会看到一行
——选择WindowsSDK版本10.0.17763.0以Windows6.1.7601为目标。
,但这似乎没有。
cmake
的命令行中是否有异常的内容?它确实存在。它发生在所有
cmake
项目中。不管Visual Studio如何,我都安装了Windows 10 SDK,但这似乎没有帮助。这很奇怪。也许将构建文件夹放在C:\中是一个奇怪的文件权限问题。您可以尝试直接在Visual Studio中打开
C:\myproj\CMakeFiles\3.13.1\CompilerIdC\CompilerIdC.vcxproj
,查看IDE是否可以读取并编译该文件。另外,如果在此文件夹中使用VisualStudio创建项目模板,这是否有效?可能是Visual Studio工作不正常?