-1

I'm trying to compile a CUDA program with nvcc but I get an error

nvcc fatal   : Cannot find compiler 'cl.exe' in PATH

I can't find any cl.exe file in the NVIDIA GPU Toolkit folder so there's no way I can add any folder containing it to the PATH - where can I obtain the cl.exe file required?

talonmies
  • 70,661
  • 34
  • 192
  • 269
Will Denny
  • 65
  • 5
  • Does this answer your question? [Error compiling CUDA from Command Prompt](https://stackoverflow.com/questions/8125826/error-compiling-cuda-from-command-prompt) – JustCode Apr 29 '23 at 19:41
  • I don't think it does - I can't find any cl.exe to begin with so there's no way I can add a folder containing it to the PATH. Also I'm not looking for any Visual Studio specific solution. – Will Denny Apr 29 '23 at 19:51
  • 1
    As per the Microsoft documentation https://learn.microsoft.com/en-us/cpp/build/reference/compiler-options?view=msvc-170 cl.exe is a tool that controls the Microsoft C++ (MSVC) C and C++ compilers and linker. cl.exe can be run only on operating systems that support Microsoft Visual Studio for Windows. So there is a dependency here. – JustCode Apr 29 '23 at 19:57
  • 1
    Please check the system requirements for CUDA, seems like you are missing a supported version of Microsoft Visual Studio. https://docs.nvidia.com/cuda/cuda-installation-guide-microsoft-windows/ – JustCode Apr 29 '23 at 20:01
  • Okay thanks, I didn't realise there was a dependency with Visual Studio. I was just using it on the command line like g++ thinking it would work rip. – Will Denny Apr 30 '23 at 10:32

1 Answers1

3

CUDA development (on any platform) requires both the nvcc compiler as well as a suitable host code compiler. On (native, not WSL2) Windows, the only host compiler supported for CUDA development is cl.exe - the host code compiler that ships with Visual Studio.

So to provide a proper environment for CUDA development on (native, not WSL2) Windows, you must install Visual Studio.

Other than that, follow the instructions provided by NVIDIA to get things set up.

An important aspect of those instructions is to install (a supported version of) Visual Studio first, then run the CUDA installer. In this way, the CUDA installer locates all supported versions of Visual Studio, and performs additional integration steps necessary to have a sane compilation environment for Windows.

After you have done that, if you intend to compile from the command line, you may still need to set your PATH environment variable correctly, and also be sure to use the -ccbin switch for nvcc to specify the location of cl.exe. Both location methods are necessary, in the general case, when compiling from the command line.

Robert Crovella
  • 143,785
  • 11
  • 213
  • 257