Search code examples
visual-studiobatch-filecmdcudanvcc

Can't set up the environment for CUDA compilation


I'm trying to build a project which requires CUDA computing, but I keep encountering an error every time I reach CUDA compilation stage. The error goes as follows:

nvcc fatal   : Could not set up the environment for Microsoft Visual Studio using 'C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.20.27508/bin/Hostx64/x64/../../../../../../../VC/Auxiliary/Build/vcvars64.bat'

It might be caused by the fact that the environment has already been set up before the nvcc build started since I'm using Visual Studio x64 Native Tools command prompt. When I launch vcvars64.bat from Visual Studio command prompt it throws an error:

%PATH%";C:\Program Files\CMake\bin;C:\Program Files\Git\cmd;C:\opencv\x64\vc15\bin;;C:\Users\grayf\AppData\Local\Microsoft\WindowsApps;C:\Users\grayf\AppData\Local\Programs\Microsoft VS Code\bin;"=="" was unexpected at this time. 

When vcvars64.bat is launched from Windows command prompt the error goes away. Seems like nvcc launches vcvars64.bat the second time, but it encounters the error, so it's unable to continue the compliation.

But I can't find a workaround because without setting up the environment by launching vcvars64.bat I'm unable to compile anything at all including a simple test C program and it doesn't even reach the nvcc compilation stage. Anyone had the same issue? I'll be glad to see your answers.


Solution

  • The issue was with my PATH variable in system variables. it contained unnecessary "\" symbols at the end of some paths and an entry that looked like "C:\torch\bin;%PATH%" when it should have been just "C:\torch\bin". The problem is gone now, nvcc sets up the environment successfuly and vcvars64.bat doesn't throw any errors even when launched from VS Command Prompt.