使用 CMake 为 VS 2017 生成解决方案的问题
Problems generating solution for VS 2017 with CMake
所以我昨天安装了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"
。然后 运行ning 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 和 运行ning vcvarsall.bat
设置环境,如下所示:
"C:\Program Files (x86)\Microsoft Visual Studio17\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64
而且我只能生成 NMake 文件而不是解决方案。
那么我怎样才能得到解决方案呢?
为什么 cl.exe
在 VC\Tools\MSVC.10.25017\bin
时报告 Version 19.10.25017
?
我正在使用 Windows 7.... 在@Florian 在评论中告诉我要调查 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.8.0-rc2\CompilerIdC\CompilerIdC.vcxproj" on node 1 (default targets).
C:\Program Files (x86)\Microsoft Visual Studio17\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.8.0-rc2\CompilerIdC\CompilerIdC.vcxproj]
Done Building Project "D:\doctest\build\CMakeFiles.8.0-rc2\CompilerIdC\CompilerIdC.vcxproj" (default targets) -- FAILED.
Build FAILED.
"D:\doctest\build\CMakeFiles.8.0-rc2\CompilerIdC\CompilerIdC.vcxproj" (default target) (1) ->
(Desktop_PlatformPrepareForBuild target) ->
C:\Program Files (x86)\Microsoft Visual Studio17\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.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.8.0-rc2\CompilerIdCXX\CompilerIdCXX.vcxproj" on node 1 (default targets).
C:\Program Files (x86)\Microsoft Visual Studio17\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.8.0-rc2\CompilerIdCXX\CompilerIdCXX.vcxproj]
Done Building Project "D:\doctest\build\CMakeFiles.8.0-rc2\CompilerIdCXX\CompilerIdCXX.vcxproj" (default targets) -- FAILED.
Build FAILED.
"D:\doctest\build\CMakeFiles.8.0-rc2\CompilerIdCXX\CompilerIdCXX.vcxproj" (default target) (1) ->
(Desktop_PlatformPrepareForBuild target) ->
C:\Program Files (x86)\Microsoft Visual Studio17\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.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.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 Studio17\Community\VC\Tools\MSVC.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 Studio17\Community\VC\Tools\MSVC.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.8.0-rc2\CompilerIdC\CompilerIdC.vcxproj]
Done Building Project "D:\doctest\build\CMakeFiles.8.0-rc2\CompilerIdC\CompilerIdC.vcxproj" (default targets) -- FAILED.
Build FAILED.
"D:\doctest\build\CMakeFiles.8.0-rc2\CompilerIdC\CompilerIdC.vcxproj" (default target) (1) ->
(Link target) ->
LINK : fatal error LNK1104: cannot open file 'ucrtd.lib' [D:\doctest\build\CMakeFiles.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.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 Studio17\Community\VC\Tools\MSVC.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 Studio17\Community\VC\Tools\MSVC.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.8.0-rc2\CompilerIdCXX\CompilerIdCXX.vcxproj]
Done Building Project "D:\doctest\build\CMakeFiles.8.0-rc2\CompilerIdCXX\CompilerIdCXX.vcxproj" (default targets) -- FAILED.
Build FAILED.
"D:\doctest\build\CMakeFiles.8.0-rc2\CompilerIdCXX\CompilerIdCXX.vcxproj" (default target) (1) ->
(Link target) ->
LINK : fatal error LNK1104: cannot open file 'ucrtd.lib' [D:\doctest\build\CMakeFiles.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
然后问题就解决了!
将我的评论变成答案
错误 -- The CXX compiler identification is unknown - No CMAKE_CXX_COMPILER could be found.
基本上意味着 CMake 无法编译一个简单的测试程序(它总是作为 identifying/validating 编译器的一部分进行编译)。
你可以看看CMakeFiles\CMakeError.log
(相对于你的二进制输出目录),错误原因应该在那里。
到目前为止我遇到的两个可能原因:
缺少管理员权限。您可以从具有管理权限的 shell 再次尝试 运行 以交叉检查您的 Visual Studio 设置是否需要管理员权限。
缺少 Windows SDK。验证您的 SDK 安装,例如检查您是否安装了任何资源编译器。它应该在类似于以下的路径中:
C:\Program Files (x86)\Microsoft SDKs\Windows\v[some version]\bin\RC.Exe
Visual Studio 2017 安装
请注意 Visual Studio 可能 不会 安装所有必需的 C++ 包,即使您 select 一个 C++ 预定义包(因为我有例如,使用 Desktop development with C++
然后在 Individual Components
选项卡下添加更多包)。
这是对我有用的 selection(VS2017 社区版,Windows 10):
如果您有使用 MFC/ATL 库的项目,您需要将其添加到 SDKs, libraries, and frameworks
子类别下:
参考资料
- The CXX compiler identification is unknown
如果您安装了 Windows 10 Creator's Update SDK,默认情况下它不会安装桌面二进制文件,以减小安装大小。 CMake 在编译时将始终尝试使用最新的 SDK,这将失败,因为它将缺少二进制文件,例如 "gdi32.lib"(这是我遇到的第一个错误)。
Microsoft 将其列为 "Known Issue",请参阅 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.
为了解决这个问题,您需要修改 Visual Studio 安装以包含 Windows 10 SDK (10.0.15063.0)
for Desktop 组件。
对于我来说,我之前安装了vs2015,之前的c编译器2015工作,当我安装vs2017时,得到同样的错误can't find compiler
。
当我在 vs2017 开发人员命令中 运行 cmake ..
时,它起作用了。
而且我可以指定generetor为vs2015或vs2017,都可以。
我遇到了类似的问题。
通过先取消选中 "Desktop Development with C++",然后重新选中 "Desktop Development with C++" 来解决。
Windows 10.0.17134 内部版本 17134; Visual Studio 2017 社区 (15.9.7)
已安装所有必需的组件
就我而言 (Wireshark building),错误出现在错误的工具集中。 CMake 确定 v141 而实际版本是 v140.
cmake -G "Visual Studio 15 2017" -T v140,host=x64 ..
可以说说我的经历。看了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
解决方案不是很优雅,但有效。 Put/copy 名称为“Directory.Build.props”的文件到 /build 文件夹,内容为:
<Project>
<PropertyGroup Label="Configuration">
<SpectreMitigation>false</SpectreMitigation>
</PropertyGroup>
</Project>
这会覆盖默认的 VS 行为并禁用 /QSpectre 编译器开关。
现在 CMake 的编译器测试 运行 通过,没有发现其他问题。
选项 2:确保安装了 Spectre 缓解库
参见:
根据我的经验,这个 CMake 工作流程问题的“基础”是(在这种情况下)确实具有误导性 错误消息“No CMAKE_C[XX]_COMPILER could被发现。"
CMakeError.log 是关键:我在那里看到“...Cl.exe /c...”,因此找到了编译器(并执行)
我的问题是 缺少 ucrt.lib(尽管 Win10 SDK 在那里;复制,而不是“安装”,我的错).
所以我昨天安装了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"
。然后 运行ningcmake --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 和 运行ning vcvarsall.bat
设置环境,如下所示:
"C:\Program Files (x86)\Microsoft Visual Studio17\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64
而且我只能生成 NMake 文件而不是解决方案。
那么我怎样才能得到解决方案呢?
为什么 cl.exe
在 VC\Tools\MSVC.10.25017\bin
时报告 Version 19.10.25017
?
我正在使用 Windows 7.... 在@Florian 在评论中告诉我要调查 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.8.0-rc2\CompilerIdC\CompilerIdC.vcxproj" on node 1 (default targets).
C:\Program Files (x86)\Microsoft Visual Studio17\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.8.0-rc2\CompilerIdC\CompilerIdC.vcxproj]
Done Building Project "D:\doctest\build\CMakeFiles.8.0-rc2\CompilerIdC\CompilerIdC.vcxproj" (default targets) -- FAILED.
Build FAILED.
"D:\doctest\build\CMakeFiles.8.0-rc2\CompilerIdC\CompilerIdC.vcxproj" (default target) (1) ->
(Desktop_PlatformPrepareForBuild target) ->
C:\Program Files (x86)\Microsoft Visual Studio17\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.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.8.0-rc2\CompilerIdCXX\CompilerIdCXX.vcxproj" on node 1 (default targets).
C:\Program Files (x86)\Microsoft Visual Studio17\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.8.0-rc2\CompilerIdCXX\CompilerIdCXX.vcxproj]
Done Building Project "D:\doctest\build\CMakeFiles.8.0-rc2\CompilerIdCXX\CompilerIdCXX.vcxproj" (default targets) -- FAILED.
Build FAILED.
"D:\doctest\build\CMakeFiles.8.0-rc2\CompilerIdCXX\CompilerIdCXX.vcxproj" (default target) (1) ->
(Desktop_PlatformPrepareForBuild target) ->
C:\Program Files (x86)\Microsoft Visual Studio17\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.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.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 Studio17\Community\VC\Tools\MSVC.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 Studio17\Community\VC\Tools\MSVC.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.8.0-rc2\CompilerIdC\CompilerIdC.vcxproj]
Done Building Project "D:\doctest\build\CMakeFiles.8.0-rc2\CompilerIdC\CompilerIdC.vcxproj" (default targets) -- FAILED.
Build FAILED.
"D:\doctest\build\CMakeFiles.8.0-rc2\CompilerIdC\CompilerIdC.vcxproj" (default target) (1) ->
(Link target) ->
LINK : fatal error LNK1104: cannot open file 'ucrtd.lib' [D:\doctest\build\CMakeFiles.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.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 Studio17\Community\VC\Tools\MSVC.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 Studio17\Community\VC\Tools\MSVC.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.8.0-rc2\CompilerIdCXX\CompilerIdCXX.vcxproj]
Done Building Project "D:\doctest\build\CMakeFiles.8.0-rc2\CompilerIdCXX\CompilerIdCXX.vcxproj" (default targets) -- FAILED.
Build FAILED.
"D:\doctest\build\CMakeFiles.8.0-rc2\CompilerIdCXX\CompilerIdCXX.vcxproj" (default target) (1) ->
(Link target) ->
LINK : fatal error LNK1104: cannot open file 'ucrtd.lib' [D:\doctest\build\CMakeFiles.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
然后问题就解决了!
将我的评论变成答案
错误 -- The CXX compiler identification is unknown - No CMAKE_CXX_COMPILER could be found.
基本上意味着 CMake 无法编译一个简单的测试程序(它总是作为 identifying/validating 编译器的一部分进行编译)。
你可以看看CMakeFiles\CMakeError.log
(相对于你的二进制输出目录),错误原因应该在那里。
到目前为止我遇到的两个可能原因:
缺少管理员权限。您可以从具有管理权限的 shell 再次尝试 运行 以交叉检查您的 Visual Studio 设置是否需要管理员权限。
缺少 Windows SDK。验证您的 SDK 安装,例如检查您是否安装了任何资源编译器。它应该在类似于以下的路径中:
C:\Program Files (x86)\Microsoft SDKs\Windows\v[some version]\bin\RC.Exe
Visual Studio 2017 安装
请注意 Visual Studio 可能 不会 安装所有必需的 C++ 包,即使您 select 一个 C++ 预定义包(因为我有例如,使用 Desktop development with C++
然后在 Individual Components
选项卡下添加更多包)。
这是对我有用的 selection(VS2017 社区版,Windows 10):
如果您有使用 MFC/ATL 库的项目,您需要将其添加到 SDKs, libraries, and frameworks
子类别下:
参考资料
- The CXX compiler identification is unknown
如果您安装了 Windows 10 Creator's Update SDK,默认情况下它不会安装桌面二进制文件,以减小安装大小。 CMake 在编译时将始终尝试使用最新的 SDK,这将失败,因为它将缺少二进制文件,例如 "gdi32.lib"(这是我遇到的第一个错误)。
Microsoft 将其列为 "Known Issue",请参阅 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.
为了解决这个问题,您需要修改 Visual Studio 安装以包含 Windows 10 SDK (10.0.15063.0)
for Desktop 组件。
对于我来说,我之前安装了vs2015,之前的c编译器2015工作,当我安装vs2017时,得到同样的错误can't find compiler
。
当我在 vs2017 开发人员命令中 运行 cmake ..
时,它起作用了。
而且我可以指定generetor为vs2015或vs2017,都可以。
我遇到了类似的问题。
通过先取消选中 "Desktop Development with C++",然后重新选中 "Desktop Development with C++" 来解决。
Windows 10.0.17134 内部版本 17134; Visual Studio 2017 社区 (15.9.7)
已安装所有必需的组件
就我而言 (Wireshark building),错误出现在错误的工具集中。 CMake 确定 v141 而实际版本是 v140.
cmake -G "Visual Studio 15 2017" -T v140,host=x64 ..
可以说说我的经历。看了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
解决方案不是很优雅,但有效。 Put/copy 名称为“Directory.Build.props”的文件到 /build 文件夹,内容为:
<Project>
<PropertyGroup Label="Configuration">
<SpectreMitigation>false</SpectreMitigation>
</PropertyGroup>
</Project>
这会覆盖默认的 VS 行为并禁用 /QSpectre 编译器开关。
现在 CMake 的编译器测试 运行 通过,没有发现其他问题。
选项 2:确保安装了 Spectre 缓解库
参见:
根据我的经验,这个 CMake 工作流程问题的“基础”是(在这种情况下)确实具有误导性 错误消息“No CMAKE_C[XX]_COMPILER could被发现。"
CMakeError.log 是关键:我在那里看到“...Cl.exe /c...”,因此找到了编译器(并执行)
我的问题是 缺少 ucrt.lib(尽管 Win10 SDK 在那里;复制,而不是“安装”,我的错).