所以我昨天安装了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.exe
在Version 19.10.25017
时报告VC\Tools\MSVC\14.10.25017\bin
?
答案 0 :(得分:19)
将我的评论转化为答案
错误-- The CXX compiler identification is unknown - No CMAKE_CXX_COMPILER could be found.
基本上意味着CMake无法编译一个简单的测试程序(它总是作为识别/验证编译器的一部分)。
您可以查看CMakeFiles\CMakeError.log
(相对于您的二进制输出目录),错误原因应该在那里。
到目前为止我遇到的两个可能的原因:
缺少管理员权限。如果您的Visual Studio设置为需要管理员权限,则可以尝试从具有管理权限进行交叉检查的shell中再次运行此命令。
缺少Windows SDK。验证您的SDK安装,例如检查您是否安装了任何资源编译器。它应该在类似于:
的路径中C:\Program Files (x86)\Microsoft SDKs\Windows\v[some version]\bin\RC.Exe
Visual Studio 2017安装
请注意,即使您选择了一个C ++预定义的包(因为我使用了Desktop development with C++
然后添加了更多包),Visual Studio也可能不安装所有必需的C ++包在Individual Components
标签下。
以下是哪些选择对我有用(VS2017 Community Edition,Windows 10):
如果您有使用MFC / ATL库的项目,则需要将其添加到SDKs, libraries, and frameworks
子类别下:
<强>参考强>
答案 1 :(得分:6)
我正在使用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\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
之后问题就消失了!
答案 2 :(得分:2)
如果安装了Windows 10 Creator的更新SDK,则默认情况下不会安装桌面二进制文件,以便减小安装大小。 CMake将在编译时始终尝试使用最新的SDK,这将失败,因为它会丢失二进制文件,例如“gdi32.lib”(这是我发生的第一个错误)。
Microsoft将此列为“已知问题”,请参阅Visual C++ Desktop Known Issues。
Windows 10 Creators Update SDK已经过重构以减少 默认安装足迹。当您通过安装此SDK时 UWP工作负载,它不会安装Win32所需的头/库 C ++桌面项目。
要解决此问题,您需要修改Visual Studio安装以包含Windows 10 SDK (10.0.15063.0)
for Desktop组件。
答案 3 :(得分:0)
对我来说,我之前安装了vs2015,之前的c编译器2015工作,当我安装vs2017时,得到了相同的错误can't find compiler
。
当我在vs2017开发人员命令中运行cmake ..
时,它可以工作。
我可以指定genretor到vs2015或vs2017,一切正常。
答案 4 :(得分:0)
我遇到了类似的问题。
首先取消选中“使用C ++进行桌面开发”,然后重新选中“使用C ++进行桌面开发”即可解决。
答案 5 :(得分:0)
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 ..
答案 6 :(得分:0)
可以告诉我的经验。阅读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缓解的”库,只想恢复以前的构建行为。
这意味着我们需要在默认情况下关闭生成带有相应编译标志的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缓解库
请参阅: