Nvcc fatal : Host compiler targets unsupported OS [On Win11, with VS 2022 & CUDA 12.2]

Hey everyone,
On a brand new win 11 installation, I installed VS 2022 build tools, then VS 2022 Community Edition (because the CUDA installer said it needs Visual Studio), then I installed the latest CUDA toolkit (12.2).
Now I’m running a build script which calls:

“nvcc” “-ccbin=C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.37.32822\bin\HostX64\x64\cl.exe” “-Xcompiler” “-nologo” “-Xcompiler” “-MD” “-G” “-Xcompiler” “-Z7” “-Xcompiler” “-Brepro” “-Xcompiler” “-W4” “-o” “D:\dev\WIP\target\debug\build\linkcuda-e0c66e31158bc793\out\eec0cf039ec00ea9-hvm2.o” “-c” “D:\dev\WIP\linkcuda/…/cuda/hvm2.cu”

This build script works on another laptop that has Win 10 and VS 2019.
But on this new Win11 laptop, I get:

Microsoft (R) C/C++ Optimizing Compiler Version 19.37.32824 for x64
Copyright (C) Microsoft Corporation. All rights reserved.

tmpxft_00003c40_00000000-2.cpp
nvcc fatal : Host compiler targets unsupported OS.
Any idea why? :)


Btw, I already saw this thread but I didn’t see a solution there.
Someone wrote there:

I have found that nvcc.exe looks for a specific file ‘VC\Auxiliary\Build\vcvarsall.bat’ relative to any parent directory of CL.exe.

Is that still true with CUDA 12.2? (That post is from 2019.)

And the last reply on that thread says:

on windows, the only supported host compiler is cl.exe, the compiler that ships with Visual Studio.

But that’s what I’m using (!)


For VS 2019, the location of vcvarsall.bat is usually C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall. bat.
But I installed VS 2022.
In the folder C:\Program Files (x86)\Microsoft Visual Studio\2022, I don’t have a folder named Community, I only have a folder named BuildTools, but I had also installed the community edition (after installing just the build tools), see this screenshot from VS Installer:

External Image

(In fact, when I search for vcvarsall.bat inside the folder C:\Program Files (x86)\Microsoft Visual Studio, I don’t have this file at all. So it doesn’t seem to be part of VS2022 anymore. I do have VsDevCmd.bat though, and my VS Dev Console works fine.)

Is NVCC still expecting this file, or is the root cause for this error another one?

I appreciate if you can help me make it work :)

I wouldn’t expect a build script to be transferable from one machine to another, unless the software installs on both machines are truly identical. Here, it is self-evident they are not.

I don’t have the expertise to tell you how to construct or re-construct a build script from scratch. And it will depend on exactly what is installed on your machine, and simply stating “VS 2022 build tools” or “VS 2022 Community Edition” is not specific enough (because those things go through version updates that matter.)

The general approach that I would try to use to sort this out would be to first verify the entire install using the general methodology that NVIDIA recommends: use some of the recommended VS sample CUDA projects and verify that you can build and run those projects correctly. If you can’t build or run those sample projects correctly, don’t bother with your build script; your basic install is broken.

If the sample projects build and run correctly, the next step I would follow is to inspect the various command lines carefully. When invoking nvcc “manually” from a command line or build script, this part of the command has to be correct:

“nvcc” “-ccbin=C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.37.32822\bin\HostX64\x64\cl.exe”

and the error you indicated “Host compiler targets unsupported OS” is somehow originating from that portion of the command line.

When invoking nvcc manually like this, its important to make sure that the version of the cl.exe tool indicated in the command, and the version that will be found by your PATH environment variable are identical. They must both indicate the exact same instance of cl.exe (and VS install tends to install various versions of cl.exe).

After verifying that, I would inspect carefully the console output from a successful VS project based build of a tool like one of the ones in the validation section of the doc I linked, or vectorAdd sample code.

Make sure you have selected to build an x64 based project, and if it were me I would also try to match the release vs. debug config as well, with what you are trying to build in the build script.
Inspect that console output for the nvcc invocation triggered from your successful build of the vectorAdd project. It should also contain a -ccbin switch, pointing to a specific instance of cl.exe. Make sure that matches what you have in your build script. If it does not, you will need to modify your build script to match, and this may also trigger you to have to go back and modify what is in the PATH environment variable.

If all of that doesn’t yield anything, then I have no further suggestions; I don’t know what the problem is. In that case, the only suggestion I have is to build whatever you need using the VS project based system that has already been covered.