Problems generating solution for VS 2017 with CMake
Solution 1
Turning my comments into an answer
The error -- The CXX compiler identification is unknown - No CMAKE_CXX_COMPILER could be found.
basically means that CMake wasn't able to compile a simple test program (which it always does as part of identifying/validating the compiler).
You can take a look into CMakeFiles\CMakeError.log
(relative to your binary output directory), the error reason should be in there.
Two possible reasons I came across so far:
Missing administrator rights. You can try running this again from a shell that has administrative rights to crosscheck if your Visual Studio was setup with the need for administrator rights.
-
Missing Windows SDK. Verify your SDK installation e.g. check that you have any Resource Compiler installed. It should be in a path similar to:
C:\Program Files (x86)\Microsoft SDKs\Windows\v[some version]\bin\RC.Exe
Visual Studio 2017 Installation
Please note the Visual Studio may not install all necessary C++ packages even when you select one of the C++ pre-defined packages (as I have e.g. used Desktop development with C++
and then added more packages under the Individual Components
tab).
Here is which selection worked for me (VS2017 Community Edition, Windows 10):
If you have projects using MFC/ATL libraries you need to add it under SDKs, libraries, and frameworks
subcategory:
References
- CMake Error at CMakeLists.txt:30 (project): No CMAKE_C_COMPILER could be found
- The CXX compiler identification is unknown
- VS 2010 and CMake: 'rc' is not recognized as an internal or external command
Solution 2
I'm using Windows 7.... And after @Florian told me in the comments to look into CMakeFiles/CMakeError.log
I managed to fix the problem!
Here is the first 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.1.548.43366
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 3/10/2017 11:05:24 AM.
Project "D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdC\CompilerIdC.vcxproj" on node 1 (default targets).
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Platforms\x64\PlatformToolsets\v141\Toolset.targets(36,5): error MSB8036: The Windows SDK version 8.1 was not found. Install the required version of Windows SDK or change the SDK version in the project property pages or by right-clicking the solution and selecting "Retarget solution". [D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdC\CompilerIdC.vcxproj]
Done Building Project "D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdC\CompilerIdC.vcxproj" (default targets) -- FAILED.
Build FAILED.
"D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdC\CompilerIdC.vcxproj" (default target) (1) ->
(Desktop_PlatformPrepareForBuild target) ->
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Platforms\x64\PlatformToolsets\v141\Toolset.targets(36,5): error MSB8036: The Windows SDK version 8.1 was not found. Install the required version of Windows SDK or change the SDK version in the project property pages or by right-clicking the solution and selecting "Retarget solution". [D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdC\CompilerIdC.vcxproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.28
Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler:
Build flags:
Id flags:
The output was:
1
Microsoft (R) Build Engine version 15.1.548.43366
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 3/10/2017 11:05:24 AM.
Project "D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdCXX\CompilerIdCXX.vcxproj" on node 1 (default targets).
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Platforms\x64\PlatformToolsets\v141\Toolset.targets(36,5): error MSB8036: The Windows SDK version 8.1 was not found. Install the required version of Windows SDK or change the SDK version in the project property pages or by right-clicking the solution and selecting "Retarget solution". [D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdCXX\CompilerIdCXX.vcxproj]
Done Building Project "D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdCXX\CompilerIdCXX.vcxproj" (default targets) -- FAILED.
Build FAILED.
"D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdCXX\CompilerIdCXX.vcxproj" (default target) (1) ->
(Desktop_PlatformPrepareForBuild target) ->
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Platforms\x64\PlatformToolsets\v141\Toolset.targets(36,5): error MSB8036: The Windows SDK version 8.1 was not found. Install the required version of Windows SDK or change the SDK version in the project property pages or by right-clicking the solution and selecting "Retarget solution". [D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdCXX\CompilerIdCXX.vcxproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.13
It seemed I needed Windows SDK version 8.1
so I installed it as a component (had only version 10 installed). But then there was another error:
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.1.548.43366
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 3/10/2017 11:17:21 AM.
Project "D:\doctest\build\CMakeFiles\3.8.0-rc2\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.10.25017\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 /errorReport:queue CMakeCCompilerId.c
CMakeCCompilerId.c
Link:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.10.25017\bin\HostX86\x64\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:X64 Debug\CMakeCCompilerId.obj
LINK : fatal error LNK1104: cannot open file 'ucrtd.lib' [D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdC\CompilerIdC.vcxproj]
Done Building Project "D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdC\CompilerIdC.vcxproj" (default targets) -- FAILED.
Build FAILED.
"D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdC\CompilerIdC.vcxproj" (default target) (1) ->
(Link target) ->
LINK : fatal error LNK1104: cannot open file 'ucrtd.lib' [D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdC\CompilerIdC.vcxproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:01.04
Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler:
Build flags:
Id flags:
The output was:
1
Microsoft (R) Build Engine version 15.1.548.43366
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 3/10/2017 11:17:22 AM.
Project "D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdCXX\CompilerIdCXX.vcxproj" on node 1 (default targets).
PrepareForBuild:
Creating directory "Debug\".
Creating directory "Debug\CompilerIdCXX.tlog\".
InitializeBuildStatus:
Creating "Debug\CompilerIdCXX.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
ClCompile:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.10.25017\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 /TP /errorReport:queue CMakeCXXCompilerId.cpp
CMakeCXXCompilerId.cpp
Link:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.10.25017\bin\HostX86\x64\link.exe /ERRORREPORT:QUEUE /OUT:".\CompilerIdCXX.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:".\CompilerIdCXX.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:".\CompilerIdCXX.lib" /MACHINE:X64 Debug\CMakeCXXCompilerId.obj
LINK : fatal error LNK1104: cannot open file 'ucrtd.lib' [D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdCXX\CompilerIdCXX.vcxproj]
Done Building Project "D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdCXX\CompilerIdCXX.vcxproj" (default targets) -- FAILED.
Build FAILED.
"D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdCXX\CompilerIdCXX.vcxproj" (default target) (1) ->
(Link target) ->
LINK : fatal error LNK1104: cannot open file 'ucrtd.lib' [D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdCXX\CompilerIdCXX.vcxproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.60
So LINK : fatal error LNK1104: cannot open file 'ucrtd.lib'
sounds a lot like I needed to install more components - and so I did:
Visual C++ runtime for UWP
Windows Universal CRT SDK
And after that the problem is gone!
Solution 3
If you have the Windows 10 Creator's Update SDK installed, it doesn't install the desktop binaries by default, in order to keep the installation size down. CMake will always try to use the latest SDK when it compiles, which will fail as it will be missing binaries such as "gdi32.lib" (that's the first error that occurs for me).
Microsoft list this as a "Known Issue", see Visual C++ Desktop Known Issues.
The Windows 10 Creators Update SDK has been refactored to reduce installation footprint by default. When you Install this SDK via the UWP workload, it will not install the headers/libs required for Win32 C++ Desktop Projects.
In order to fix the problem, you need to modify the Visual Studio installation to include the Windows 10 SDK (10.0.15063.0)
for Desktop component.
Solution 4
Can tell my experience. After reading CMakeFiles/CMakeError.log found an error
LINK : fatal error LNK1104: cannot open file 'MSVCRTD.lib'
and what's more important - warning
Common7\IDE\VC\VCTargets\Microsoft.CppBuild.targets(402,5):
warning MSB8038: Spectre mitigation is enabled but Spectre mitigated libraries
are not found.
Verify that the Visual Studio Workload includes the Spectre mitigated libraries.
Option 1: I have no intention to use "Spectre-mitigated" libraries and want just to restore previous build behavior.
That means that we need to turn off generating Visual Studio project with correspondent compilation flags on by default since CMake does that to check whether compiler exists and operational.
Luckily found a thread on support forum: https://developercommunity.visualstudio.com/content/problem/348985/installing-wdk-1809-enabled-spectre-mitigation-fla.html
Solution is not very elegant, but works. Put/copy file with name 'Directory.Build.props' to /build folder with content:
<Project>
<PropertyGroup Label="Configuration">
<SpectreMitigation>false</SpectreMitigation>
</PropertyGroup>
</Project>
That overrides default VS behavior and disables /QSpectre compiler switch.
Now CMake's compiler test run passes and no other issues found.
Option 2: ensure that Spectre mitigation libraries installed
See:
Solution 5
I encountered a similar problem.
It was solved by first un-checking "Desktop Development with C++", and then re-checking "Desktop Development with C++".
Related videos on Youtube
Comments
-
onqtam over 2 years
So I installed Visual Studio 2017 yesterday. I also installed CMake 3.7.2 which supports VS 2017.
My VS installation is with the
Game development with C++
workflow + a few other components:I've also added the CMake stuff (but I don't think I even needed it - since I'm using CMake as a standalone tool to just generate the VS solutions) and MSBuild (I had
msbuild.exe
even before adding that component - so not sure what exactly does that additional component do).With VS 2015 I was able to just run
cmake .
from a normal command prompt for a solution.With VS 2017 the workflow changes - I've read this post from Microsoft.
So I tried the following:
- I opened the
Developer Command Prompt for VS 2017
and from it I rancmake . -G "NMake Makefiles"
. Then runningcmake --build .
compiled everything properly. -
When I tried the following in the prompt:
cmake . -G "Visual Studio 15 2017 Win64"
to force the creation of a solution I got the following errors:-- The C compiler identification is unknown -- The CXX compiler identification is unknown CMake Error at CMakeLists.txt:3 (project): No CMAKE_C_COMPILER could be found. CMake Error at CMakeLists.txt:3 (project): No CMAKE_CXX_COMPILER could be found. -- Configuring incomplete, errors occurred!
I also tried setting up the environment using vswhere.exe and running
vcvarsall.bat
like this:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64
and again I could only generate NMake files and not a solution.
So how can I get a solution?
And why does
cl.exe
reportVersion 19.10.25017
when it's inVC\Tools\MSVC\14.10.25017\bin
?-
tambre about 7 years
cl.exe
reports the compiler version. The directory it's in is the overall compiler version. Please note that the CMake bundled with VS15 is modified by the VS team and is based on CMake 3.6, IIR. It's not supported as an official CMake version. I recommend that you stick for the meantime with the normal CMake 3.8 which works properly with VS15 and also generates proper solution files. Also, beware of this bug in VS15. -
onqtam about 7 years@tambre well
cmake --version
reports3.7.2
which is the latest official release (3.8 being a RC) - it's the one I've installed separately from VS. But I will try with 3.8 now. -
onqtam about 7 years@tambre - nope - still the same problem with CMake 3.8 RC
-
tambre about 7 yearsSounds like you VS15 installation might be borked. Try "Repairing" it.
-
onqtam about 7 years@tambre I tried removing it and installing it again (with restarting the PC in between)
-
tambre about 7 yearsAre you sure you're using the CMake 3.8 RC that you installed and not the one included with VS15? Run
cmake --version
to make sure. -
onqtam about 7 yearsthats exactly how I check the verison. And now that I reinstalled the whole VS 2017 I even skipped the cmake stuff from it - just the
Game development with C++
workflow is installed. -
Florian about 7 yearsIt look like you're doing in-source-builds. So one possibility could be, that you are trying to switch from
NMake
toVisual Studio
generators in the same directory (which won't work). Can you try again with making e.g. a newbuild
sub-directory and runcmake ..
from there (starting generation process from scratch)? Or e.g. automate it with a script. -
onqtam about 7 years@Florian well I simplified the case - I do use out-of-source builds and always clear the directory between invocations of cmake with a different generator (or compiler/toolchain). I also tried reinstalling VS 2017... my next guess is to try the same on another machine and if it works there - will probably reinstall windows..... :|
-
Florian about 7 yearsI don't think you need to reinstall Windows. There are numerous other reasons this could happen. One is e.g. around administrator rights. You can try running this again from a shell that has administrative rights to crosscheck if your Visual Studio was setup with the need for administrator rights. And can you please add the
CMakeFiles\CMakeError.log
content to your question? There must be some error reason in there. -
onqtam about 7 years@Florian thank you for pointing me to look there! See my edit - I fixed the problem! Add an answer in the lines of "check the cmake error log - and what OS are you using? you might need more components" and I will select it - u deserve the rep! I also tried the same setup on a different clean machine with Windows 7 and the same happened.
-
ComicSansMS about 7 years@onqtam Instead of editing the answer into the question, you should post it as an answer and then accept your own answer. There is nothing wrong with answering your own questions.
-
Florian about 7 years@onqtam You are welcome. Added an answer.
- I opened the
-
onqtam about 7 yearsI'm still keeping my answer though :D
-
joell about 7 yearsIn the newest installer (1.5.30308.1) the option for
Windows Universal CRT SDK
andWindows 8.1 SDK
are bundled intoWindows 8.1 SDK and UCRT SDK
. Also theC++/CLI support
isn't required for CMake to detect the VS C and C++ compilers. -
Maxim about 7 yearsJust small note to others: If you already installed VS studio community edition, you still can add this packages: Open VS studion installer, select VS Community Edition -> click modify. Than select required packages (see comment) and click "modify"
-
ceztko about 7 yearsWith 8.1 SDK and regular Win32 applications adding just "Windows Universal CRT SDK" is enough. The other component is for UWP apps.
-
nagates over 6 yearsawesome, this fixed it for me to.
-
Yongwei Wu about 6 yearsChecking "Windows Universal CRT SDK" (only) worked for me.
-
François Beaune over 5 yearsThank you! Partially as a note to my future self: When invoked with the
Visual Studio 14 2015 Win64
code generator under a VS 2017 command prompt, CMake could not find the C/C++ compilers because it was gettingLNK1104: Cannot open file 'ucrtd.lib'
errors when compiling its compiler detection code. The solution was to installWindows Universal CRT SDK
. -
nevilad over 2 yearsThe mentioned thread for Directory.Build.props says this file should be created in the "root directory of your project". Where did you found the solution with the "/build folder"?