I ran into this error after Visual Studio 2022 updated. It seems this occurs when compiling against newer versions of MSVC. You’re supposed to be able to change this via Visual Studio → Tools → Get Tools and Features…, going into the “Individual components” tab and unchecking the installation that is causing problems, but no matter how many times I did that the latest version was still installed on my PC. I ended up going here and manually removing the 14.39 directory:
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC
and then I was able to compile. What you want to see is this in the Build output:
Using Visual Studio 2022 14.38.33135 toolchain (C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130) and Windows 10.0.18362.0 SDK (C:\Program Files (x86)\Windows Kits\10).
Not this:
Using Visual Studio 2022 14.39.33521 toolchain (C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519) and Windows 10.0.18362.0 SDK (C:\Program Files (x86)\Windows Kits\10).
EDIT: You do have to have A version of MSVC installed in the Visual Studio Installer, I have “MSVC v143 - VS 2022 C++ x64/x86 build tools (v14.38-17.8)”, as well as a couple of older versions, but the compiler should pick the most recent installed one automatically.