CMAKE错误:"无法打开源文件":'CMakeCCompilerId.c'

3
我正在尝试运行一个可以在Windows和Linux上运行的CMAKE项目。当我尝试运行CMAKE以生成构建文件时,我会收到以下错误信息:

enter image description here

我查看了其他关于这个错误的帖子,大部分建议重新安装Visual Studio,但这并没有解决问题。
查看错误日志后,我得到了以下信息:
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 1/11/2019 15:31:21.
Project "C:\Users\user\Documents\projects\dsa_opengl_examples\build\CMakeFiles\3.13.2\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\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\CL.exe /c /nologo /W0 /WX- /diagnostics:classic /Od /D _MBCS /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"Debug\\" /Fd"Debug\vc141.pdb" /Gd /TC /FC /errorReport:queue CMakeCCompilerId.c
  CMakeCCompilerId.c
c1 : fatal error C1083: Cannot open source file: 'CMakeCCompilerId.c': No such file or directory [C:\Users\user\Documents\projects\dsa_opengl_examples\build\CMakeFiles\3.13.2\CompilerIdC\CompilerIdC.vcxproj]
Done Building Project "C:\Users\user\Documents\projects\dsa_opengl_examples\build\CMakeFiles\3.13.2\CompilerIdC\CompilerIdC.vcxproj" (default targets) -- FAILED.

Build FAILED.

"C:\Users\user\Documents\projects\dsa_opengl_examples\build\CMakeFiles\3.13.2\CompilerIdC\CompilerIdC.vcxproj" (default target) (1) ->
(ClCompile target) -> 
  c1 : fatal error C1083: Cannot open source file: 'CMakeCCompilerId.c': No such file or directory [C:\Users\user\Documents\projects\dsa_opengl_examples\build\CMakeFiles\3.13.2\CompilerIdC\CompilerIdC.vcxproj]

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:01.02

有没有人知道如何解决c1 : fatal error C1083: Cannot open source file: 'CMakeCCompilerId.c': No such file or directory的错误?


你需要提取一个 [mcve]。 - Ulrich Eckhardt
@UlrichEckhardt:CMake在编译器检测方面的错误大多是由环境设置或cmake参数引起的;项目代码与此类问题无关。 - Tsyvarev
“我正在尝试在Linux上运行一个在Windows上工作的CMAKE项目。” - 呃?你展示的输出明显属于Windows,而不是Linux。 - Tsyvarev
@Tsyvarev 抱歉,我的意思是在 Windows Linux 上。已更新问题。 - Startec
2个回答

1

我遇到了完全相同的问题。

在跟随@serg06的部分解决方案(并将其翻译成中文)之后,我找到了适合我的解决方法:

我使用的是来自WSL的git和来自cmd的cmake,不确定为什么会有问题,但是安装Windows版的git并从cmd重新克隆我的存储库解决了这个问题。希望能对你有所帮助!


0
经过三个小时的搜索,我终于找到了一个(部分)解决方案。它所说的只有:
  • 复制粘贴您的项目文件夹(带有CMakeLists.txt的那个)到您的桌面上。
  • 导航到该位置并再次运行cmake命令。
  • 它可以工作!

为什么它在桌面上可以工作,但在原来的位置上却不行呢?毫无头绪。我以为这是一个权限问题,所以我将我的原始文件夹的权限最大化了。(给“每个人”和我自己完全的权限+给了我自己文件夹和子文件夹的所有权。)没有任何区别。

看来我们只能将我的项目放在C:\Users\Myname\下的某个地方了。

如果这不能解决您的问题,我找到的其他一些解决方案是:

  • 重新安装cmake
  • 将cmake降级至3.14.x
  • 重新安装VS
  • 确保指定正确的makefile生成器。(例如,如果您调用cmake -G“Visual Studio 12”。,则表示VS 2013(VS 12 = VS 2013)。有关所有生成器,请参见cmake --help。)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接