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

Hi,

Long story short, I’ve been struggling with a project in both VS2017 and VS2019, with both CMake 3.18 and CMake 3.21.1.

In VS2019, in the CMakeSettings.json file…

  • If i set CMake generator to “Visual Studio 16 2019 Win64” CMake cache generation succeeds and i’m able to build and run.
  • If i set CMake generator to “Visual Studio 15 2017 Win64” CMake cache generation fails:
    1> CMake generation started for configuration: ‘x64-Debug’.
    1> Command line: “C:\WINDOWS\system32\cmd.exe” /c “%SYSTEMROOT%\System32\chcp.com 65001 >NUL && “c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\commonextensions\microsoft\cmake\CMake\bin\cmake.exe” -G “Visual Studio 15 2017” -A x64 -DCMAKE_CONFIGURATION_TYPES:STRING=“Debug” -DCMAKE_INSTALL_PREFIX:PATH=“D:\s\CMakeBuilds\f1e0f0a6-b40c-47b9-ac01-10c27884e354\install\x64-Debug” “D:\s” 2>&1”
    1> Working directory: D:\s\CMakeBuilds\f1e0f0a6-b40c-47b9-ac01-10c27884e354\build\x64-Debug
    1> [CMake] CMakeLists debug 1
    1> [CMake] – Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19042.
    1> [CMake] – The C compiler identification is unknown
    1> [CMake] – The CXX compiler identification is unknown
    1> [CMake] CMake Error at D:\s\CMakeLists.txt:7 (project):
    1> [CMake] No CMAKE_C_COMPILER could be found.
    1> [CMake]
    1> [CMake]
    1> [CMake]
    1> [CMake] CMake Error at D:\s\CMakeLists.txt:7 (project):
    1> [CMake] No CMAKE_CXX_COMPILER could be found.

Why can’t it find these compilers?
Thanks.

this. is. killing. me.

1 Like

Since you are using CMakeSettings.json it’s hard to answer your question, without even knowing what your json looks like.

Also it’s worth considering replacing your usage of CMakeSettings.json with CMakePresets.json

  • CMakeSettings.json is Visual Studio exclusive, and was basically a stop gap until CMakePresets.json was introduced in 3.19

Hi, thanks for the reply!

Here’s the contents of my CMakeSettings.json file:
{
“configurations”: [
{
“name”: “win64-Debug”,
“generator”: “Visual Studio 15 2017 Win64”,
“configurationType”: “Debug”,
“inheritEnvironments”: [ “msvc_x64_x64” ],
“buildRoot”: “${projectDir}\CMakeBuilds\${workspaceHash}\build\${name}”,
“installRoot”: “${projectDir}\CMakeBuilds\${workspaceHash}\install\${name}”,
“cmakeCommandArgs”: “”,
“buildCommandArgs”: “-m -v:minimal”,
“ctestCommandArgs”: “”
}
]
}

I have tried using the CMakePresets.json method, the reason I went back to CMakeSettings.json was because it defaulted to the ninja generator, which has never worked for me. There doesn’t seem to be an editor built into VS for CMakePresets.json like there is for CMakeSettings.json. I could give it another try though. I haven’t seen what/if the advantages of CMakePresets over CMakeSettings.

Thanks again buildSystemPerson.

Let’s forget about CMakeSettings.json for a second.

Can you build a VS 2019/2017 project with CMake standalone?

cd foobar/
cmake -B build/vs2019 -G "Visual Studio 16 2019"
cmake -B build/vs2017 -G "Visual Studio 15 2017"

If this doesn’t work it means you don’t have the necessary software installed on your system. You’ll need to look at your VS installations.

If that doesn’t work consider refreshing your installations:

Also I understand this is frustrating. It’s just how Microsoft decided to make their C++ build environment. They decided to tie their compiler to their IDE. That approach has trade offs.

At our company we actually don’t even rely on VS for our drivers to compile using MSVC. Since it’s a pain to ensure developers use the same compiler. We actually run our own packaging system around MSVC to ensure we have easily reproducible builds with strict semantic versioning control. This means extra work to understand the MSVC C++ environment, but it also means we don’t have to worry about updating Visual Studio breaking developer builds. Or dev A uses a slightly different compiler then dev B. Or devs using a different compiler than our CI.

Did you install Visual Studio 15 2017?
It’s sound like what you really want is to use Visual Studio 16 2019 IDE but with the 2017 toolset. I’m pretty sure you’d want to use the -T option.

If I remember correctly, there was a subtle change in the generator from Visual Studio 2017 to 2019:

  • 2017: -G "Visual Studio 15 2017 Win64" (NOT -G "Visual Studio 15 2017" -A x64)

  • 2019: -G "Visual Studio 16 2019" -A x64

@alvaropalmaaste according to the docs it’s fine to use -A with VS2017:

The CMAKE_GENERATOR_PLATFORM variable may be set, perhaps via the cmake(1) -A option, to specify a target platform name (architecture). For example:

    cmake -G "Visual Studio 15 2017" -A Win32

    cmake -G "Visual Studio 15 2017" -A x64

    cmake -G "Visual Studio 15 2017" -A ARM

    cmake -G "Visual Studio 15 2017" -A ARM64

For compatibility with CMake versions prior to 3.1, one may specify a target platform name optionally at the end of the generator name. This is supported only for:

Visual Studio 15 2017 Win64

    Specify target platform x64.
Visual Studio 15 2017 ARM

    Specify target platform ARM.

Hi buildSystemPerson,

I get the same result on the commandline as I do in VS…
C:\Program Files\CMake\bin>cmake -S D:\s -B D:\s\build\vs2017 -G “Visual Studio 15 2017”
CMakeLists debug 11
– Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19042.
– The C compiler identification is unknown
– The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:7 (project):
No CMAKE_C_COMPILER could be found.

CMake Error at CMakeLists.txt:7 (project):
No CMAKE_CXX_COMPILER could be found.

– Configuring incomplete, errors occurred!
See also “D:/s/build/vs2017/CMakeFiles/CMakeOutput.log”.
See also “D:/s/build/vs2017/CMakeFiles/CMakeError.log”.

The beginning contents of 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 9/7/2021 12:29:58 PM.
Project “D:\s\build\vs2017\CMakeFiles\3.21.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\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX86\x86\CL.exe /c /nologo /W0 /WX- /diagnostics:classic /Od /Oy- /D _MBCS /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"Debug\" /Fd"Debug\vc141.pdb" /Gd /TC /analyze- /FC /errorReport:queue CMakeCCompilerId.c
CMakeCCompilerId.c
Link:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX86\x86\link.exe /ERRORREPORT:QUEUE /OUT:".\CompilerIdC.exe" /INCREMENTAL:NO /NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:“level=‘asInvoker’ uiAccess=‘false’” /manifest:embed /PDB:".\CompilerIdC.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:".\CompilerIdC.lib" /MACHINE:X86 /SAFESEH Debug\CMakeCCompilerId.obj
LINK : fatal error LNK1104: cannot open file ‘MSVCRTD.lib’ [D:\s\build\vs2017\CMakeFiles\3.21.1\CompilerIdC\CompilerIdC.vcxproj]
Done Building Project “D:\s\build\vs2017\CMakeFiles\3.21.1\CompilerIdC\CompilerIdC.vcxproj” (default targets) – FAILED.

Build FAILED.

Do you have all the relevant VS 2017 software installed on your machine?

I’ve been assuming not since the beginning, but I don’t know for certain what is needed…

Could you go into the modify section for VS 2017? We need to know the specific components you installed. Just having the IDE doesn’t show anything. For example here is my local VS 2019:

You need the compiler (MSVC) and a version of the SDK, and you most likely a debugger/profiler. Not sure if those last 2 are needed for CMake.

Here’s what I have:

I’m honestly stuck… it looks like you have the right things for VS 2017.

Although I have never personally used CMake with 2 versions of Visual Studio on my computer.

Maybe consider repairing your Visual Studio installation? One time a coworker of mine was having an issue with CMake / Visual Studio and this fixed it.

I’ve read that installing the WDK can cause problems.

1 Like

Looks like someone is having a similar issue here:

I repaired my VS2017, rebooted, and same result.

Not sure what the host is, but I tried these:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community>cmake -S D:\s -B D:\s\build\vs2017 -G “Visual Studio 15 2017” -A x64 -T host=x64
CMakeLists debug 11
– Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19042.
– The C compiler identification is unknown
– The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:7 (project):
No CMAKE_C_COMPILER could be found.

CMake Error at CMakeLists.txt:7 (project):
No CMAKE_CXX_COMPILER could be found.

– Configuring incomplete, errors occurred!
See also “D:/s/build/vs2017/CMakeFiles/CMakeOutput.log”.
See also “D:/s/build/vs2017/CMakeFiles/CMakeError.log”.

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community>cmake -S D:\s -B D:\s\build\vs2017 -G “Visual Studio 15 2017” -A x64 -T host=x86
CMakeLists debug 11
– Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19042.
– The C compiler identification is unknown
– The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:7 (project):
No CMAKE_C_COMPILER could be found.

CMake Error at CMakeLists.txt:7 (project):
No CMAKE_CXX_COMPILER could be found.

– Configuring incomplete, errors occurred!
See also “D:/s/build/vs2017/CMakeFiles/CMakeOutput.log”.
See also “D:/s/build/vs2017/CMakeFiles/CMakeError.log”.

Lets reduce the variables by not explicitly using -A or -T

And lets cd into the proper directory. Also lets delete any possible build artifacts I can’t see on your machine.

cd D:/s
rm build/ -recurse -force
cmake -B build/ -G “Visual Studio 15 2017”

Same issue:

D:\s>cmake -B build/ -G “Visual Studio 15 2017”
CMakeLists debug 11
– Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19042.
– The C compiler identification is unknown
– The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:7 (project):
No CMAKE_C_COMPILER could be found.

CMake Error at CMakeLists.txt:7 (project):
No CMAKE_CXX_COMPILER could be found.

– Configuring incomplete, errors occurred!
See also “D:/s/build/CMakeFiles/CMakeOutput.log”.
See also “D:/s/build/CMakeFiles/CMakeError.log”.