我刚刚安装了Windows 10 Creators Update(版本10.0.15063).
我安装了多个版本的Visual Studio(2012年,2013年,2015年和2017年).我几周前才安装了VS 2017.
问题
在“VS2015 x64本机命令提示符”中运行时,CMake(版本3.8.1)不再找到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命令提示符中找到:
> 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环境变量的内容:
>在VS 2013命令提示符内,PATH包含
C:\Program Files (x86)\Windows Kits\8.1\bin\x64
>在VS 2017命令提示符内,PATH包含
C:\Program Files (x86)\Windows Kits\10\bin\x64
C:\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\x64
>但在VS 2015命令提示符中,PATH仅包含
C:\Program Files (x86)\Windows Kits\10\bin\x64
其中不包含rc.exe.
问题
>这是一个已知问题还是特定于我的系统?
> Windows 10 Creators Update可能会在系统中安装,卸载或更改(可能是与Windows SDK相关的东西)会触发此问题?
>什么是解决这个问题的干净方法?
编辑:安装VS 2017组件: