--rc=rc --mt=CMAKE_MT-NOTFOUND



I found the cause of the bug!

TLDR: Registry editing has been disabled by your administrator.

Link to the Visual Studio issue with full details


I’ve had this problem for a while. So it’s not specific to a CMake release or version of visual studio. It’s just MSVC specific.

When using the native tools command prompts provided by visual studio I’m getting this strange error:

>cmake -B build/nin -G "Ninja"
-- The CXX compiler identification is MSVC 19.30.30705.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.30.30705/bin/Hostx64/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.30.30705/bin/Hostx64/x64/cl.exe - broken
CMake Error at C:/cmake/share/cmake-3.22/Modules/CMakeTestCXXCompiler.cmake:62 (message):
  The C++ compiler

    "C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.30.30705/bin/Hostx64/x64/cl.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: D:/foobar/build/nin/CMakeFiles/CMakeTmp

    Run Build Command(s):D:/develop/dk/win/ninja/1.10.2/ninja.exe cmTC_9ce07 && [1/2] Building CXX object CMakeFiles\cmTC_9ce07.dir\testCXXCompiler.cxx.obj
    [2/2] Linking CXX executable cmTC_9ce07.exe
    FAILED: cmTC_9ce07.exe
    cmd.exe /C "cd . && C:\cmake\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\cmTC_9ce07.dir --rc=rc --mt=CMAKE_MT-NOTFOUND --manifests  -- C:\PROGRA~1\MIB055~1\2022\PROFES~1\VC\Tools\MSVC\1430~1.307\bin\Hostx64\x64\link.exe /nologo CMakeFiles\cmTC_9ce07.dir\testCXXCompiler.cxx.obj  /out:cmTC_9ce07.exe /implib:cmTC_9ce07.lib /pdb:cmTC_9ce07.pdb /version:0.0 /machine:x64  /debug /INCREMENTAL /subsystem:console  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
    RC Pass 1: command "rc /fo CMakeFiles\cmTC_9ce07.dir/manifest.res CMakeFiles\cmTC_9ce07.dir/manifest.rc" failed (exit code 0) with the following output:
    The system cannot find the file specified
    ninja: build stopped: subcommand failed.

Basically CMake fails to build a simple example project due to issues around the resource compiler and the CMAKE_MT program it requires.

It sounds like you have the compiler, but are missing the Windows SDK. You’ll need to install that component in the Visual Studio installer.

I have the Windows SDK installed. I’m able to get Visual Studio Generator builds working fine that use the resource compiler.

Out of curiosity how does CMake find the Resource Compiler? Could it get confused if I have another exe with the name ‘rc.exe’ in my path?

It just expects it to be in PATH AFAIK.

vcvarsall.bat normally puts a Windows SDK in the PATH. CMake expects this for command-line buildsystem generators like Ninja.

** Visual Studio 2022 Developer Command Prompt v17.1.0
** Copyright (c) 2021 Microsoft Corporation

C:\Program Files\Microsoft Visual Studio\2022\Professional>rc.exe /?
'rc.exe' is not recognized as an internal or external command,
operable program or batch file.

Seems like it’s not putting it in my PATH I just repaired my VS2022 installation as well.

Normally I’d chalk this down to a (it’s just me) issue. But I’ve had coworkers contact me with the exact same problem. Perhaps this is a VS issue.

Oh! It might not be the SDK. There’s a “build tools” component that is needed. I think you might need the “Latest” version (with that label, not the highest number).

Here is the list of everything I currently have installed:

  • MSVC v143 - VS2022 C++ x64/x86 build tools
  • Windows 10 SDK (10.0.19041.0)
  • Just-In-Time Debugger
  • C++ profiling tools
  • C++ CMake tools for Windows
  • C++ ATL for latest v143 build tools
  • C++ AddressSanitizer
  • C++ MFC for latest v143 build tools
  • C++/CLI support for v143 build tools
  • C++ Modules for v143 build tools

Yet I still get the aforementioned errors. I’m going to try completely installing Visual Studio from scratch.

I think there was one that was just “latest build tools” (without a toolchain version). That may be what you need (I think the right tools still get used, but this is what hooks in wherever that is needed).

I just checked with another coworker who had the same components installed as me. Seems like it’s local to my machine.

I completely re-installed Visual Studio 2022 Enterprise Edition.

I’m able to build a project that takes advantage of the resource compiler via the visual studio generator but not via the ninja generator.

As mentioned by @brad.king I end up finding RC.exe via the SDK:

PS C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x64> .\rc.exe /?

Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Copyright (C) Microsoft Corporation.  All rights reserved.

However, that path is NOT getting added to the path in developer command prompts.

** Visual Studio 2022 Developer PowerShell v17.1.0
** Copyright (c) 2021 Microsoft Corporation
PS C:\Program Files\Microsoft Visual Studio\2022\Enterprise> $env:path.split(";")
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\\Extensions\Microsoft\IntelliCode\CLI
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.31.31103\bin\HostX64\x64
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\VC\VCPackages
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\bin\Roslyn
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Team Tools\Performance Tools\x64
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Team Tools\Performance Tools
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\\MSBuild\Current\Bin\amd64
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\

FWIW this looks like a Visual Studio issue/bug. And isn’t caused by CMake. CMake can’t do anything about users not having properly setup their PATH.

I found the cause of the bug!

TLDR: Registry editing has been disabled by your administrator.

Link to the Visual Studio issue with full details

Looks like Microsoft isn’t interested in fixing the issue from their side.

As a developer not having access to the registry is an uncommon scenario, it is suggested that the effected developers modify [VisualStudio Install Directory]\Common7\Tools\vsdevcmd\core\winsdk.bat.
By manually changing “set WindowsSdkDir=” to "set WindowsSdkDir=[path to windows sdk] IE: “C:\Program Files (x86)\Windows Kits\10” you should restore functionality for the command line. Note that depending on your project you may have to manually set additional variables in this file.

@brad.king / @ben.boeckel would a CMake side change be appropriate? I can make a PR for it.

Perhaps, but what do you propose CMake should do about this?

Perhaps something like this.

    message(FATAL_ERROR "Ensure SDK is installed AND registry editing is enabled!")

IIRC we do support -DCMAKE_RC_COMPILER=rc, and may not always convert that to an absolute path. In that case we’d assume rc is going to be in the PATH, but if(EXISTS) won’t work. Maybe we need to always convert CMAKE_RC_COMPILER to an absolute path as we do for other language compilers. If it fails to be found, then we can produce the nicer error.

1 Like

I’ll see if I can wrangle up a PR this weekend to address this