NVCC fails to set up the environment for Microsoft Visual Studio

I’m trying to build a library using Visual Studio but nvcc.exe keeps throwing the following error:

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

I tried running the command using Windows PowerShell instead of Visual Studio; it is as follows (since I’m using cmake I set verbose to ON in order to obtain further context):

.\cmake.exe -D verbose:BOOL=ON -D "CCBIN:PATH=C:\Program Files (x86)\Microsoft Visual Studio017\Community\VC\Tools\MSVC4.16.27023\bin\Hostx64\x64" -D build_configuration:STRING=Release -D generated_file:STRING=C:/openpose/build/src/openpose/CMakeFiles/openpose.dir/face/Release/openpose_generated_renderFace.cu.obj -D generated_cubin_file:STRING=C:/openpose/build/src/openpose/CMakeFiles/openpose.dir/face/Release/openpose_generated_renderFace.cu.obj.cubin.txt -P C:/openpose/build/src/openpose/CMakeFiles/openpose.dir/face/openpose_generated_renderFace.cu.obj.Release.cmake

This is the full output (line 5 contains said error):

-- Removing C:/openpose/build/src/openpose/CMakeFiles/openpose.dir/face/Release/openpose_generated_renderFace.cu.obj
"C:/Program Files/CMake/bin/cmake.exe" -E remove C:/openpose/build/src/openpose/CMakeFiles/openpose.dir/face/Release/openpose_generated_renderFace.cu.obj
-- Generating dependency file: C:/openpose/build/src/openpose/CMakeFiles/openpose.dir/face/openpose_generated_renderFace.cu.obj.NVCC-depend
"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.0/bin/nvcc.exe" -M -D__CUDACC__ "C:/Program Files (x86)/OpenPose/src/openpose/face/renderFace.cu" -o C:/openpose/build/src/openpose/CMakeFiles/openpose.dir/face/openpose_generated_renderFace.cu.obj.NVCC-depend -ccbin "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx64/x64" -m64 -Dopenpose_EXPORTS -DBOOST_ALL_NO_LIB -DUSE_CAFFE -DUSE_CUDA -Xcompiler ,\"/W4\",\"/EHsc\",\"/MP\",\"/MD\",\"/Ox\",\"/DNDEBUG\",\"/Ot\",\"/Oi\",\"/Gy\",\"/Z7\" -DNVCC "-IC:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.0/include" "-IC:/Program Files (x86)/OpenPose/include" "-IC:/Program Files (x86)/OpenPose/3rdparty/windows/opencv/include" "-IC:/Program Files (x86)/OpenPose/3rdparty/windows/caffe/include" "-IC:/Program Files (x86)/OpenPose/3rdparty/windows/caffe/include2" "-IC:/Program Files (x86)/OpenPose/3rdparty/windows/caffe3rdparty/include"
nvcc fatal   : Could not set up the environment for Microsoft Visual Studio using 'C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx64/x64/../../../../../../../VC/Auxiliary/Build/vcvars64.bat'
CMake Error at C:/openpose/build/src/openpose/CMakeFiles/openpose.dir/face/openpose_generated_renderFace.cu.obj.Release.cmake:219 (message):
  Error generating
  C:/openpose/build/src/openpose/CMakeFiles/openpose.dir/face/Release/openpose_generated_renderFace.cu.obj

I have Visual Studio 2017 Community, CUDA 10.0 and cuDNN 7.5 installed on a Windows 10 machine with an NVIDIA GeForce GTX 1050, driver version 430.86. CUDA was installed after VS2017 to make sure all required CUDA files were created for that version of the IDE; cuDNN files were pasted inside the CUDA installation folder, following the documentation instructions. The vcvars64.bat file exists in that location and it runs alright in the command prompt.

I have since restarted the PC; reinstalled VS2017 with all required modules; installed VS2015 along with a CUDA and cuDNN reinstall. None of these solutions worked for me.

In the meantime, I installed VS2017 and CUDA on a clean Windows 10 PC with an NVIDIA Quadro K420 and I could build the same project just fine, so I believe the issue is related with the environment variables on my PC? I checked them and confronted with the working clean PC and did not find any missing variable, though.

Also, I checked the forums and found this topic, but none of the solutions presented seemed to work for me.

Any idea what the issue might be?

Hi, I have almost the same problem. Do you have a solution now?

Thanks!