61

I'm trying to compile a cuda test program on Windows 7 via Command Prompt, I'm this command:

nvcc test.cu

But all I get is this error:

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

What may be causing this error?

GennSev
  • 1,586
  • 4
  • 20
  • 29
  • 2
    if you get another error "Cannot find corecrt.h" after fixing this issue, check out https://stackoverflow.com/questions/38290169/cannot-find-corecrt-h-universalcrt-includepath-is-wrong – Alexander Pacha Dec 01 '16 at 09:34

7 Answers7

58

You will need to add the folder containing the "cl.exe" file to your path environment variable. For example:

C:\Program Files\Microsoft Visual Studio 10.0\VC\bin

Edit: Ok, go to My Computer -> Properties -> Advanced System Settings -> Environment Variables. Here look for "PATH" in the list, and add the path above (or whatever is the location of your cl.exe).

Tudor
  • 61,523
  • 12
  • 102
  • 142
  • 1
    Ok, but how do I add it? I'm used to work on linux, so I'm unused to the ways of windows now... – GennSev Nov 14 '11 at 18:49
  • Fine, but now I got another error: ` nvcc fatal : Visual Studio configuration file '(null)' could not be found for installation at 'C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin/../..' ` – GennSev Nov 14 '11 at 20:09
  • 1
    Nevermind, I got rid of it just by passing --machine 32 as a parameter to nvcc – GennSev Nov 14 '11 at 20:15
  • When I search for this file, I see different versions in different sizes. How can one determine which one belongs? Also, I tried adding the path of one to the Environment Variable, but I still get this error. – Jack Feb 07 '13 at 03:23
  • 1
    @Jackalope: Which paths are you getting for cl.exe? It should be the one that ends with \bin. – Tudor Feb 07 '13 at 08:40
  • 2
    @Jackalope Try to run vcvars.bat in the bin directory. It sets up some environment variables used by cl.exe. – deathly809 Jul 30 '14 at 07:28
  • What should be the variable name? The key? – notgiorgi Oct 05 '16 at 10:32
  • 1
    @notgiorgi: The variable name is PATH. Just append the path to cl.exe at the end of the existing value. – Tudor Oct 06 '16 at 08:44
  • in my system there is no folder `bin` in `VC`, take a look : [here](https://i.stack.imgur.com/Ccxvw.png) – Maifee Ul Asad Nov 22 '19 at 07:23
36

For new Visual Studio cl.exe is present in path => C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\bin\Hostx64\x64

x64 is for 64bit

x86 is for 32bit

trevorp
  • 1,161
  • 1
  • 14
  • 19
23

Solve this problem by adding this options to nvcc

nvcc x.cu ...   -ccbin "D:\Program Files\Microsoft Visual Studio 11.0\VC\bin"

for example my compiler is VS2012. and cl.exe is in this dir

Prof. Hell
  • 729
  • 12
  • 19
  • Can you clarify what you mean by "edit this problem"? – skrrgwasme Jul 29 '14 at 21:06
  • Adding the `\VC\bin\` folder to the PATH environment variable did not work for me (Win7). Your solution, however, worked just fine! I was trying to compile some code for MATLAB. Thanks! – Dev-iL Jan 18 '15 at 12:38
  • bro. study cuda toolkit to know all of this options and better work. It's our duty to help and answer each other. thanks you too. – Prof. Hell Jan 19 '15 at 13:37
  • or a more recent path: `C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin` – Garrett Oct 04 '18 at 17:33
  • one occasion where neither path entries nor -ccbin will help either is when building for x86 but nvcc.exe won't support it for the given version of cl.exe (in my case: nvcc.exe from CUDA 10.0.130 won't build 32 bit binaries with cl.exe from VS2015) – StuporMundi Jun 05 '19 at 13:26
5

cl.exe is Microsoft's C/C++ compiler. So the problem is that you don't have that installed where the command line can find it.

Chris Dodd
  • 119,907
  • 13
  • 134
  • 226
1

Solve this problem by adding the path to environment variables, which can vary slightly depending in the version of visual studio installed in your system, and are you using 32bit or 64bit system

C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64
Arnab Das
  • 149
  • 3
  • 3
  • 1
    I am on the exact version that you are of MSVC but I still get the error. If I just run `cl.exe` I get no error – MindStudio Jan 25 '23 at 00:46
1

nvcc is only a front end for the CUDA specific part of the program. It must invoke a full compiler to finish the job. In this case it cannot find the Visual Studio compiler 'cl.exe'

Check paths, nvcc documentation etc.

Steve Fallows
  • 6,274
  • 5
  • 47
  • 67
0

I see that this is an old question but I recently got this error on my Visual Studio 2012 when I tried to build my CUDA project. Apparently I had changed my CUDA project to the Nov 2012 pack, changing it back to the v110 that it usually is by default fixed this error.

In Visual Studio, left click on the CUDA project, ->properties->Configuration Properties-> General -> Platform toolset, and choose: Visual Studio 2012 (v110).

I could probably get it to work with the Nov 2012 pack, but the CUDA code does not use any of the additional functions of that pack, so it is not necessary. (That pack contains the variadic templates for C++11.)

Donna
  • 41
  • 3