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.
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.
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.
@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.
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.
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:
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.
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”.
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”.