简体   繁体   中英

CMAKE error: "Cannot open source file" : 'CMakeCCompilerId.c'

I am trying to run a CMAKE project that works on Windows and on Linux. When I try to run CMAKE to generate the build files I get the following error:

在此处输入图片说明

I checked other posts for this error, most of which suggested reinstalling Visual Studio, but that did not help.

Checking the error logs gave me this:

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

Does anyone know how I can solve the c1 : fatal error C1083: Cannot open source file: 'CMakeCCompilerId.c': No such file or directory error?

I had the same exact issue.

After following @serg06 link to the partial solution (and translating it from Chinese) I have found the solution for me:

I was using git from WSL and cmake from cmd, not sure why that is a problem, but installing git for windows and recloning my repo from cmd fixed the issue. Hope that helps!

After 3 hours of searching, I finally found a (partial) solution . All it says is:

  • Copy paste your project folder (the one with CMakeLists.txt) to your desktop.
  • Navigate there and run your cmake command again.
  • It works!

Why does it work on the desktop but not in its original position? No clue. I thought it was a permissions problem, so I MAXED out the permissions on my original folder. (Gave "Everyone" and myself full permissions + gave myself folder & subfolder ownership.) No difference.

Guess we'll just have to settle with having my project somewhere under C:\\Users\\Myname\\ .

If that doesn't solve your problem, some other solutions I found were:

  • Reinstalling cmake
  • Downgrading cmake to 3.14.x
  • Reinstalling VS
  • Making sure to specify the correct makefile generator. (Eg if you call cmake -G "Visual Studio 12" . , you're referring to VS 2013 (VS 12 = VS 2013). See cmake --help for all generators.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM