在 VS 2015 命令提示符中不再找到 rc.exe

我刚刚安装了 Windows 10 创意者更新(版本 10.0.15063).

I just installed Windows 10 Creators Update (version 10.0.15063).

我安装了多个版本的 Visual Studio(2012、2013、2015 和 2017).我几周前才安装了 VS 2017.

I have multiple versions of Visual Studio installed (2012, 2013, 2015 and 2017). I installed VS 2017 only a couple weeks ago.

CMake(3.8.1 版)在VS2015 x64 本机命令提示符"中运行时不再找到 C/C++ 编译器(在 VS 2017 命令提示符中运行时它确实正常工作).

CMake (version 3.8.1) no longer finds the C/C++ compiler when run inside a "VS2015 x64 Native Command Prompt" (it does work properly when run inside a VS 2017 command prompt).

CMakeLists.txt 的内容:

project (test)
add_executable (test test.cpp)

(test.cpp 的内容无关.)

CMake 调用,在 VS2015 x64 本机命令提示符中:

CMake invocation, in a VS2015 x64 Native Command Prompt:

> 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就很清楚失败的原因了:

Analysis

The reason of the failure is clear when looking at CMakeFiles/CMakeError.log:

ClCompile:
  C:Program Files (x86)Microsoft Visual Studio 14.0VCinx86_amd64CL.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"Debugvc140.pdb" /Gd /TC /errorReport:queue CMakeCCompilerId.c
  CMakeCCompilerId.c
Link:
  C:Program Files (x86)Microsoft Visual Studio 14.0VCinx86_amd64link.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 DebugCMakeCCompilerId.obj
LINK : fatal error LNK1158: cannot run 'rc.exe' [D:devcmaketestuildCMakeFiles3.8.1CompilerIdCCompilerIdC.vcxproj]

rc.exe(资源编译器)未找到.确实,在同一个 VS 2015 命令提示符下:

rc.exe (Resource Compiler) is not found. Indeed, in the same VS 2015 command prompt:

> where rc.exe
INFO: Could not find files for the given pattern(s).

虽然它是在 VS 2013 命令提示符中找到的:

While it is found in a VS 2013 command prompt:

> where rc.exe
C:Program Files (x86)Windows Kits8.1inx64c.exe
C:Program Files (x86)Windows Kits8.1inx86c.exe

和 VS 2017 命令提示符:

and a VS 2017 command prompt:

> where rc.exe
C:Program Files (x86)Windows Kits10in10.0.15063.0x64c.exe

在各种VS命令提示中检查PATH环境变量的内容:

Checking the content of the PATH environment variables in various VS command prompts:

  • 在 VS 2013 命令提示符中,PATH 包含

C:Program Files (x86)Windows Kits8.1inx64

  • 在 VS 2017 命令提示符中,PATH 包含

    C:Program Files (x86)Windows Kits10inx64
    C:Program Files (x86)Windows Kits10in10.0.15063.0x64
    

  • 但是在 VS 2015 命令提示符中,PATH 只包含

    C:Program Files (x86)Windows Kits10inx64
    

    不包含rc.exe.

    1. 这是一个已知问题还是特定于我的系统?

    1. Is this a known issue or is it specific to my system?

    Windows 10 Creators Update 可能会在系统中安装、卸载或更改哪些会触发此问题的内容(可能与 Windows SDK 相关)?

    What could Windows 10 Creators Update possibly install, uninstall or alter in the system (perhaps something related to Windows SDKs) that would trigger this problem?

    有什么干净的方法可以解决这个问题?

    What is a clean way to resolve this?

    已安装 VS 2017 组件:

    Installed VS 2017 components:

    推荐答案

    花了一些时间在安装了 Win10 Creators Edition 和 VS2010、VS2013、VS2015 和 VS2017 的三台机器上查看这个问题,它在两台机器上工作,但在第三.所有人都安装了 VS2015 Update 3,并且都应该使用相同的选项进行安装.

    Spent some time looking at this on three machines with Win10 Creators Edition and VS2010, VS2013, VS2015 and VS2017 installed, where it works on two machines and fails on the third. All had VS2015 Update 3 and all should have been installed with the same options.

    运行以下批处理文件

    C:Program Files (x86)Microsoft Visual Studio 14.0VCinamd64vcvars64.bat
    

    应该为 VS2015 x64 环境设置正确的环境.这应该添加

    should setup the correct environment for VS2015 x64 environment. This should add

    C:Program Files (x86)Windows Kits10inx64
    

    到路径.这是 rc.exe 应该在的地方.然而,在我出现故障的机器上 rc.exe 从这里丢失,但它确实存在于

    to the PATH. This is where rc.exe should be. However on my failing machine rc.exe was missing from here, but it did exist in

    C:Program Files (x86)Windows Kits10in10.0.15063.0x64
    

    我回去后感觉这是一个设置问题,我重新运行了 VS2015 Update 3 设置并告诉它添加

    I went back and feeling like this was a setup issue I re-ran the VS2015 Update 3 setup and told it to add

    Windows 和 Web 开发 -> 通用 Windows 应用程序开发工具 -> 工具 (1.4.1) 和 Windows 10 SDK (10.0.14393)

    这导致 rc.exe 和相关文件出现在

    this caused rc.exe and related files to appear in

    C:Program Files (x86)Windows Kits10inx64
    

    C:Program Files (x86)Windows Kits10in10.0.15063.0x64c.exe
    

    C:Program Files (x86)Windows Kits10inx64c.exe
    

    给出相同的版本号10.0.10011.16384

    不确定为什么原始安装中缺少 rc.exe,但重新运行安装并添加其他 SDK 为我修复了它.看起来像

    Not sure why rc.exe was missing from the original install, but re-running the install and adding the other SDK fixed it for me. It looks like

    C:Program Files (x86)Windows Kits10inx64c.exe
    

    应该是默认的 rc.exe 但它不是由以前的安装设置的.

    should be the default rc.exe but it was not setup by a previous install.

  • 相关文章