No CMAKE_C_COMPILER could be found. No CMAKE_CXX_COMPILER could be found.

I’m left with the impression that when the user PATH contains all of those items previously mentioned then Visual Studio projects do not work correctly regardless if it is a CMake or Visual Studio template project. Maybe something about the PATH breaks the MSBuild command line tools in Visual Studio 2017.

" Maybe something about the PATH breaks the MSBuild command line tools in Visual Studio 2017."

A while ago I had an issue with my builds caused by having a polluted path.

I had an exe called rc.exe in my path. However, it wasn’t Microsoft’s RC (Resource Compiler), it was just a executable named rc.exe and CMake tried to use it to compile a project. And it obviously failed since my rc.exe had nothing to do with C/C++ compilation. Once I removed the offending PATH from my system and rebooted everything worked fine.

Maybe it’s a similar thing?

Thanks again BSP,
If this is the case, it seems like I should be able to find the offending path in a hypothetical log/error file before the first error message?
I have both MSBuild project build output verbosity and MSBuild project build log file verbosity set to Diagnostic but these settings don’t seem to apply to the CMakeError.log file. Is there a way to increase the verbosity of the CMake configure/build steps?

https://cmake.org/cmake/help/latest/manual/cmake.1.html#options

Add --trace-expand to your configure step for CMake. It will log absolutely everything. I recommend
redirecting the output to a file.

In my CMakeSettings.json file, i have added that option:

This CMake_gencache_debug.txt file is ~1.5MB. I tried attaching it to this reply, but I get this message: Sorry, new users can not upload attachments.
I’ve looked through it, but nothing is jumping out at me. Anything I should look out for?
Thanks

Ctrl-f for error messages

message(FATAL_ERROR
error
etc.

Also you are looking specifically for the logging around compiler identification. Since that is what is failing.

I get the following messages over and over, like 20 times in this file:

Build started 9/15/2021 12:58:20 PM.
Project “D:\s\CMakeBuilds\f1e0f0a6-b40c-47b9-ac01-10c27884e354\build\win64-Debug\CMakeFiles\3.20.21032501-MSVC_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:
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
TRACKER : error TRK0005: Failed to locate: “CL.exe”. The system cannot find the file specified. [D:\s\CMakeBuilds\f1e0f0a6-b40c-47b9-ac01-10c27884e354\build\win64-Debug\CMakeFiles\3.20.21032501-MSVC_2\CompilerIdC\CompilerIdC.vcxproj]

Done Building Project “D:\s\CMakeBuilds\f1e0f0a6-b40c-47b9-ac01-10c27884e354\build\win64-Debug\CMakeFiles\3.20.21032501-MSVC_2\CompilerIdC\CompilerIdC.vcxproj” (default targets) – FAILED.

Build FAILED.

“D:\s\CMakeBuilds\f1e0f0a6-b40c-47b9-ac01-10c27884e354\build\win64-Debug\CMakeFiles\3.20.21032501-MSVC_2\CompilerIdC\CompilerIdC.vcxproj” (default target) (1) →
(ClCompile target) →
TRACKER : error TRK0005: Failed to locate: “CL.exe”. The system cannot find the file specified. [D:\s\CMakeBuilds\f1e0f0a6-b40c-47b9-ac01-10c27884e354\build\win64-Debug\CMakeFiles\3.20.21032501-MSVC_2\CompilerIdC\CompilerIdC.vcxproj]

0 Warning(s)
1 Error(s)

Time Elapsed 00:00:00.55

Okay well this one errored out due to failing to locate the compiler “CL.exe”.

What do the logs look like when your PATH is clean? You should be able to diff them and get an idea from there.

How do I clean the PATH?

Oh sorry, I wasn’t aware that would apply to VS (outside of the powershell).
Anyway, I cleaned the path as per post #28, and I get the same result:

“Oh sorry, I wasn’t aware that would apply to VS (outside of the powershell).”

It won’t. It makes sense you get the same result.

Create your VS solution from powershell to simplify things for now. Otherwise you will have to modify your actual PATH in windows. Which I’m assuming you don’t want to do.

Oh ok.
So you are talking about running the following in powershell?:
cmake -B build/ -G "Visual Studio 15 2017"

Yes.

Run 1 time with your regular path. Run 1 time with your modified path. And compare those results with the --trace-expand.

I didn’t mention: on September 9th I moved C:\Program Files\CMake\bin to the top of the PATH environment varaible list, and it was able to locate the compilers in powershell with the new long PATH:


I haven’t changed my PATH environment variable since September 9th.
It still works in powershell (with the post Sept 9 PATH), but not in VS (with the post Sept 9 PATH).

Okay if it works in powershell but not in Visual Studio thats an indicator that Visual Studio maybe modifying the environment. Try printing the environment variable PATH in your CMake script to see if Visual Studio is doing something unexpected.

message(STATUS “PATH = $ENV{PATH}”)

I added that line to the first line of my CMakeLists.txt file, here is a comparison between the microsoft PATH (left) and what VS adds (right):

and here is the the stuff added to the end: