Problems generating solution for VS 2017 with CMak

2019-03-14 11:46发布

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?

4条回答
手持菜刀,她持情操
2楼-- · 2019-03-14 12:24

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!

查看更多
Lonely孤独者°
3楼-- · 2019-03-14 12:32

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.

Install Creator's Update SDK for Desktop

查看更多
叼着烟拽天下
4楼-- · 2019-03-14 12:43

For me ,I installed vs2015 before,and the c compiler 2015 work before,when i install vs2017, get the same error can't find compiler. And when i run cmake .. in the vs2017 developer command,it works. And i can specify generetor to vs2015 or vs2017,it all works.

查看更多
冷血范
5楼-- · 2019-03-14 12:46

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

查看更多
登录 后发表回答