我刚刚安装了Windows 10 Creators Update (版本号为10.0.15063)。
我安装了多个版本的Visual Studio (2012、2013、2015和2017),但只有几周前才安装了VS 2017。
问题
CMake(版本为3.8.1)在“VS2015 x64 Native Command Prompt”中运行时无法找到C/C++编译器(但在VS 2017命令提示符中运行正常)。
复现步骤
CMakeLists.txt
的内容:
project (test)
add_executable (test test.cpp)
(test.cpp
的内容不相关。)
在 VS2015 x64 本机命令提示符下进行的 CMake 调用:
> mkdir build
> cd build
> cmake -G "Visual Studio 14 2015 Win64" ..
CMake的输出:
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:1 (project):
No CMAKE_C_COMPILER could be found.
CMake Error at CMakeLists.txt:1 (project):
No CMAKE_CXX_COMPILER could be found.
-- Configuring incomplete, errors occurred!
See also "D:/dev/cmaketest/build/CMakeFiles/CMakeOutput.log".
See also "D:/dev/cmaketest/build/CMakeFiles/CMakeError.log".
分析
查看 CMakeFiles/CMakeError.log
后,故障原因就很明显了:
ClCompile:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64\CL.exe /c /nologo /W0 /WX- /Od /D _MBCS /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"Debug\\" /Fd"Debug\vc140.pdb" /Gd /TC /errorReport:queue CMakeCCompilerId.c
CMakeCCompilerId.c
Link:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64\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 LNK1158: cannot run 'rc.exe' [D:\dev\cmaketest\build\CMakeFiles\3.8.1\CompilerIdC\CompilerIdC.vcxproj]
rc.exe
(资源编译器)未找到。确实,在相同的VS 2015命令提示符下:
> where rc.exe
INFO: Could not find files for the given pattern(s).
虽然在 VS 2013 命令提示符中找到了它: is。
> where rc.exe
C:\Program Files (x86)\Windows Kits\8.1\bin\x64\rc.exe
C:\Program Files (x86)\Windows Kits\8.1\bin\x86\rc.exe
和VS 2017命令提示符:
> where rc.exe
C:\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\x64\rc.exe
在不同的VS命令提示符中检查PATH
环境变量的内容:
Inside a VS 2013 command prompt,
PATH
containsC:\Program Files (x86)\Windows Kits\8.1\bin\x64
Inside a VS 2017 command prompt,
PATH
containsC:\Program Files (x86)\Windows Kits\10\bin\x64 C:\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\x64
But inside a VS 2015 command prompt,
PATH
only containsC:\Program Files (x86)\Windows Kits\10\bin\x64
which does not contain
rc.exe
.
问题
这是一个已知的问题还是只存在于我的系统中?
Windows 10创作者更新可能会安装、卸载或更改系统中的哪些内容(也许与Windows SDK相关),会导致出现这个问题?
有什么干净利落的方法来解决这个问题?
编辑:已安装VS 2017组件:
C:\Program Files (x86)\Windows Kits\10\bin\x64\rc.EXE
中。 - DaveCleland