【问题标题】:Problems generating solution for VS 2017 with CMake使用 CMake 为 VS 2017 生成解决方案的问题
【发布时间】:2017-07-30 18:33:25
【问题描述】:

所以我昨天安装了 Visual Studio 2017。我还安装了支持 VS 2017 的 CMake 3.7.2。

我的 VS 安装是使用 Game development with C++ 工作流 + 一些其他组件:

我还添加了 CMake 的东西(但我认为我什至不需要它 - 因为我使用 CMake 作为一个独立工具来生成 VS 解决方案)和 MSBuild(我之前有 msbuild.exe添加该组件 - 所以不确定该附加组件到底是做什么的)。

在 VS 2015 中,我可以在普通命令提示符下运行 cmake . 以获得解决方案。

在 VS 2017 中,工作流程发生了变化 - 我已阅读 this post from Microsoft

所以我尝试了以下方法:

  • 我打开Developer Command Prompt for VS 2017 并从中运行cmake . -G "NMake Makefiles"。然后运行 ​​cmake --build . 正确编译所有内容。
  • 当我在提示符中尝试以下操作时:cmake . -G "Visual Studio 15 2017 Win64" 强制创建解决方案时出现以下错误:

    -- 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!
    

我还尝试使用vswhere.exe 设置环境并像这样运行vcvarsall.bat

“C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat”amd64

我只能生成 NMake 文件而不是解决方案。

那么我该如何解决呢?

为什么cl.exeVC\Tools\MSVC\14.10.25017\bin 中时会报告Version 19.10.25017

【问题讨论】:

  • cl.exe 报告编译器版本。它所在的目录是整体编译器版本。请注意,与 VS15 捆绑的 CMake 由 VS 团队修改,基于 CMake 3.6,IIR。它不支持作为官方 CMake 版本。我建议您同时坚持使用普通的 CMake 3.8,它可以与 VS15 一起正常工作并生成正确的解决方案文件。另外,请注意this bug in VS15
  • @tambre well cmake --version 报告 3.7.2 这是最新的官方版本(3.8 是 RC)——它是我与 VS 分开安装的。但我现在会尝试 3.8。
  • @tambre - 不 - CMake 3.8 RC 仍然存在同样的问题
  • 我认为您不需要重新安装 Windows。发生这种情况的原因还有很多。一个是例如围绕管理员权限。您可以尝试从具有管理权限的 shell 再次运行它,以交叉检查您的 Visual Studio 是否设置为需要管理员权限。您能否将CMakeFiles\CMakeError.log 内容添加到您的问题中?那里一定有一些错误原因。
  • @onqtam 不要将答案编辑到问题中,您应该将其作为答案发布,然后接受您自己的答案。回答自己的问题并没有错。

标签: c++ visual-studio visual-c++ cmake visual-studio-2017


【解决方案1】:

把我的 cmets 变成答案

错误 -- The CXX compiler identification is unknown - No CMAKE_CXX_COMPILER could be found. 基本上意味着 CMake 无法编译简单的测试程序(它总是作为识别/验证编译器的一部分)。

您可以查看CMakeFiles\CMakeError.log(相对于您的二进制输出目录),错误原因应该在那里。

到目前为止,我遇到了两个可能的原因:

  1. 缺少管理员权限。您可以尝试从具有管理权限的 shell 再次运行它,以交叉检查您的 Visual Studio 是否设置为需要管理员权限。

  2. 缺少 Windows SDK。验证您的 SDK 安装,例如检查您是否安装了任何资源编译器。它应该在类似于以下的路径中:

    C:\Program Files (x86)\Microsoft SDKs\Windows\v[some version]\bin\RC.Exe
    

Visual Studio 2017 安装

请注意,Visual Studio 可能不会安装所有必要的 C++ 包,即使您选择了其中一个 C++ 预定义包(例如,我使用了 Desktop development with C++,然后在Individual Components 标签)。

以下是适合我的选择(VS2017 社区版,Windows 10):

如果您有使用 MFC/ATL 库的项目,则需要将其添加到 SDKs, libraries, and frameworks 子类别下:

参考文献

【讨论】:

  • 我仍然保留我的答案:D
  • 在最新的安装程序 (1.5.30308.1) 中,Windows Universal CRT SDKWindows 8.1 SDK 的选项绑定到 Windows 8.1 SDK and UCRT SDK。此外,CMake 不需要 C++/CLI support 来检测 VS C 和 C++ 编译器。
  • 小提示:如果你已经安装了 VS studio 社区版,你仍然可以添加这个包:打开 VS studion 安装程序,选择 VS 社区版 -> 点击修改。比选择所需的包(见评论)并点击“修改”
  • 谢谢!部分作为对我未来自我的说明:当在 VS 2017 命令提示符下使用 Visual Studio 14 2015 Win64 代码生成器调用时,CMake 找不到 C/C++ 编译器,因为它在编译其编译器检测代码时遇到了 LNK1104: Cannot open file 'ucrtd.lib' 错误。解决方案是安装Windows Universal CRT SDK
【解决方案2】:

我使用的是 Windows 7.... 在 @Florian 在 cmets 中告诉我查看 CMakeFiles/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.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

看来我需要Windows SDK version 8.1,所以我将它作为一个组件安装(只安装了版本 10)。但随后又出现了一个错误:

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

所以LINK : fatal error LNK1104: cannot open file 'ucrtd.lib' 听起来很像我需要安装更多组件 - 所以我做到了:

  • Visual C++ runtime for UWP
  • Windows Universal CRT SDK

然后问题就消失了!

【讨论】:

  • 对于 8.1 SDK 和常规 Win32 应用程序,只添加“Windows 通用 CRT SDK”就足够了。另一个组件用于 UWP 应用。
  • 检查“Windows 通用 CRT SDK”(仅)对我有用。
【解决方案3】:

如果您安装了 Windows 10 Creator's Update SDK,则默认情况下它不会安装桌面二进制文件,以减小安装大小。 CMake 在编译时将始终尝试使用最新的 SDK,这将失败,因为它会丢失诸如“gdi32.lib”之类的二进制文件(这是我遇到的第一个错误)。

Microsoft 将此列为“已知问题”,请参阅 Visual C++ Desktop Known Issues

Windows 10 Creators Update SDK 已经过重构,以减少 默认安装占用空间。当您通过 UWP 工作负载,它不会安装 Win32 所需的头文件/库 C++ 桌面项目。

为了解决此问题,您需要修改 Visual Studio 安装以包含 Windows 10 SDK (10.0.15063.0) for Desktop 组件。

【讨论】:

  • 太棒了,这为我修好了。
【解决方案4】:

可以说说我的经历。看完CMakeFiles/CMakeError.log发现有错误

LINK : fatal error LNK1104: cannot open file 'MSVCRTD.lib'

还有更重要的——警告

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.  

选项 1:我无意使用“Spectre-mitigated”库,只想恢复以前的构建行为。

这意味着我们需要在默认情况下关闭生成具有相应编译标志的 Visual Studio 项目,因为 CMake 这样做是为了检查编译器是否存在并且是否可操作。

幸运地在支持论坛上找到了一个帖子:https://developercommunity.visualstudio.com/content/problem/348985/installing-wdk-1809-enabled-spectre-mitigation-fla.html

解决方案不是很优雅,但很有效。将名称为“Directory.Build.props”的文件放入/复制到 /build 文件夹,内容为:

<Project>
  <PropertyGroup Label="Configuration">
    <SpectreMitigation>false</SpectreMitigation>
  </PropertyGroup>
</Project>

这会覆盖默认的 VS 行为并禁用 /QSpectre 编译器开关。

现在 CMake 的编译器测试运行通过,没有发现其他问题。

选项 2:确保已安装 Spectre 缓解库

见:

【讨论】:

  • Directory.Build.props 提到的线程说这个文件应该在“你的项目的根目录”中创建。您在哪里找到了“/build 文件夹”的解决方案?
【解决方案5】:

我遇到了类似的问题。

首先取消选中“使用 C++ 进行桌面开发”,然后重新选中“使用 C++ 进行桌面开发”即可解决。

【讨论】:

    【解决方案6】:

    Windows 10.0.17134 Build 17134; Visual Studio 2017 社区 (15.9.7)

    所有必需的组件都已安装

    在我的例子中 (Wireshark building),错误出现在错误的工具集中。 CMake 确定 v141 而实际版本是 v140

    cmake -G "Visual Studio 15 2017" -T v140,host=x64 ..
    

    【讨论】:

      【解决方案7】:

      对我来说,我之前安装了 vs2015,而 c 编译器 2015 之前工作,当我安装 vs2017 时,得到相同的错误can't find compiler。 当我在 vs2017 开发人员命令中运行 cmake .. 时,它可以工作。 我可以将生成器指定为 vs2015 或 vs2017,一切正常。

      【讨论】:

        【解决方案8】:

        根据我的经验,这个 CMake 工作流问题的“基础”是(在这种情况下)真正误导错误消息“找不到 CMAKE_C[XX]_COMPILER。”

        CMakeError.log 是关键:我在那里看到“...Cl.exe /c...”,所以找到了(并执行了)编译器

        我的问题是 缺少 ucrt。lib(虽然 Win10 SDK 在那里;复制,而不是“安装”,我的错)。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-01-09
          • 2011-10-13
          • 1970-01-01
          相关资源
          最近更新 更多