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

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:\Windows\Microsoft.NET\Framework64\v4.0.30319
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\
C:\ProgramData\Oracle\Java\javapath
C:\WINDOWS\system32
C:\WINDOWS
C:\WINDOWS\System32\Wbem
C:\WINDOWS\System32\WindowsPowerShell\v1.0\
C:\WINDOWS\System32\OpenSSH\

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.

if (NOT EXISTS ${CMAKE_RC_COMPILER})
    message(FATAL_ERROR "Ensure SDK is installed AND registry editing is enabled!")
endif()

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

It’s not really related to the actual issue of the original post, but I ended up here with the same symptoms after a rather fresh installation of a new developer machine.

Running

reg query "HKLM\SOFTWARE\WOW6432Node\Microsoft\Microsoft SDKs\Windows\v10.0"

on the command line finally revealed that the Python3 installer inserted the python/scripts folder at the very beginning of the PATH environment variable, resulting in reg.py being executed instead of the reg command line tool when CMake was trying to query the registry for the path to the WindowsSDK… Moving the python folders further back in PATH fixed it immediately.

So maybe this helps other people ending up here to figure out what’s wrong more quickly.

That is…cruel. Have you filed an issue with the provider of that installer about this?

I got this resolved by adding “C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x64” to PATH, but now it throws below error:

CMake Error at C:/Program Files/Microsoft Visual Studio/2022/Professional/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.26/Modules/CMakeTestCCompiler.cmake:67 (message):
  The C compiler

    "C:/Users/hchambet/work/aocc/llvm-build/Release/bin/clang-cl.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: C:/Users/hchambet/work/aocc/classic_flang/runtime/libpgmath/build/CMakeFiles/CMakeScratch/TryCompile-17pqcp

    Run Build Command(s):C:/PROGRA~1/MIB055~1/2022/PROFES~1/Common7/IDE/COMMON~1/MICROS~1/CMake/Ninja/ninja.exe -v cmTC_c8719 && [1/2] C:\Users\hchambet\work\aocc\llvm-build\Release\bin\clang-cl.exe  /nologo   /DWIN32 /D_WINDOWS /W3  /MDd /Zi /Ob0 /Od /RTC1 /showIncludes /FoCMakeFiles\cmTC_c8719.dir\testCCompiler.c.obj /FdCMakeFiles\cmTC_c8719.dir\ -c -- C:\Users\hchambet\work\aocc\classic_flang\runtime\libpgmath\build\CMakeFiles\CMakeScratch\TryCompile-17pqcp\testCCompiler.c
    [2/2] cmd.exe /C "cd . && "C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_c8719.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100190~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100190~1.0\x64\mt.exe --manifests  -- C:\PROGRA~1\MIB055~1\2022\PROFES~1\VC\Tools\MSVC\1436~1.325\bin\Hostx64\x64\link.exe /nologo CMakeFiles\cmTC_c8719.dir\testCCompiler.c.obj  /out:cmTC_c8719.exe /implib:cmTC_c8719.lib /pdb:cmTC_c8719.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 ."
    FAILED: cmTC_c8719.exe
    cmd.exe /C "cd . && "C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_c8719.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100190~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100190~1.0\x64\mt.exe --manifests  -- C:\PROGRA~1\MIB055~1\2022\PROFES~1\VC\Tools\MSVC\1436~1.325\bin\Hostx64\x64\link.exe /nologo CMakeFiles\cmTC_c8719.dir\testCCompiler.c.obj  /out:cmTC_c8719.exe /implib:cmTC_c8719.lib /pdb:cmTC_c8719.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 ."
    LINK Pass 1: command "C:\PROGRA~1\MIB055~1\2022\PROFES~1\VC\Tools\MSVC\1436~1.325\bin\Hostx64\x64\link.exe /nologo CMakeFiles\cmTC_c8719.dir\testCCompiler.c.obj /out:cmTC_c8719.exe /implib:cmTC_c8719.lib /pdb:cmTC_c8719.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 /MANIFEST /MANIFESTFILE:CMakeFiles\cmTC_c8719.dir/intermediate.manifest CMakeFiles\cmTC_c8719.dir/manifest.res" failed (exit code 1104) with the following output:
    LINK : fatal error LNK1104: cannot open file 'kernel32.lib'
    ninja: build stopped: subcommand failed.

I tried adding library path to “PATH”, but it didn’t work. Any idea on how to solve this?

The Microsoft toolchain requires a lot more than just PATH. You should really use vcvarsall.bat to load the toolchain environment.