Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems generating solution for VS 2017 with CMake

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:

individual_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 ran cmake . -G "NMake Makefiles". Then running cmake --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 report Version 19.10.25017 when it's in VC\Tools\MSVC\14.10.25017\bin?

like image 821
onqtam Avatar asked Mar 09 '17 16:03

onqtam


People also ask

Can't find any instance of Visual Studio CMake error?

In general the key to solving this problem always seems to be reinstalling/modifying Visual Studio, which ends up repairing the environment so that cmake can find the Visual Studio instance.

Does CMake work with Visual Studio 2019?

Visual Studio uses a CMake configuration file to drive CMake generation and build. CMakePresets. json is supported by Visual Studio 2019 version 16.10 or later and is the recommended CMake configuration file.

Do I need CMake with Visual Studio?

CMake is a build tool in a special way. It can create makefiles and build them but you can also tell cmake to create a visual studio solution if you like. The same goes with external programs. They are the choice of the maintainer of the library you use and there are no standards for things like code generation.

How do I create a CMake project in Visual Studio?

On the Visual Studio main menu, choose File > Open > CMake. Navigate to the CMakeLists. txt file in the root of the bullet3 repo you just downloaded. As soon as you open the folder, your folder structure becomes visible in the Solution Explorer.


2 Answers

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:

  1. 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.

  2. 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):

enter image description here

If you have projects using MFC/ATL libraries you need to add it under SDKs, libraries, and frameworks subcategory:

enter image description here

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
like image 171
Florian Avatar answered Sep 19 '22 09:09

Florian


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!

like image 39
onqtam Avatar answered Sep 21 '22 09:09

onqtam