4

I'm trying to build a CMake project using Visual Studio (open folder mode). Nvcc is required to build the project.

I get the following error:

  The CUDA compiler

    "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/bin/nvcc.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: [PROJECT_PATH]/build/Test_Release/CMakeFiles/CMakeTmp

    Run Build Command:"C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe" "cmTC_d4aa6"
    [1/3] Building CUDA object CMakeFiles\cmTC_d4aa6.dir\main.cu.obj
    FAILED: CMakeFiles/cmTC_d4aa6.dir/main.cu.obj 
    cmd.exe /C "C:\PROGRA~1\NVIDIA~2\CUDA\v10.1\bin\nvcc.exe     -x cu -c main.cu -o CMakeFiles\cmTC_d4aa6.dir\main.cu.obj && C:\PROGRA~1\NVIDIA~2\CUDA\v10.1\bin\nvcc.exe     -x cu -M main.cu -MT CMakeFiles\cmTC_d4aa6.dir\main.cu.obj -o CMakeFiles\cmTC_d4aa6.dir\main.cu.obj.d"
    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'
    ninja: build stopped: subcommand failed.



  CMake will not be able to correctly generate this project.        C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.13/Modules/CMakeTestCUDACompiler.cmake   46  

I tried different combinations of Nvidia CUDA Toolkit (10.0, 10.1) and Microsoft Visual Studio (2017 - MSVC 14.16, 2019 - MSVC 14.20). None of these gets rid of the error.

I built successfully the project on other machines, with the same versions of visual studio and nvcc.

Ryno
  • 403
  • 2
  • 7
  • 11

5 Answers5

4

I had the same problem, here is how I fixed it.

Check your PATH environment variable. In my system PATH one of the values was surrounded with double quotes. It was the path to an old DirectX 9 library that I had been using to build an old Winamp Visualizer lol.

Be careful, because Windows 10 hides the fact that some PATH values are surrounded with double quotes. When it is showing you the parsed list of values, it doesn't show the double quotes. You have to click the "Edit Text..." button to see the PATH variable as one long string. I also removed any trailing "\" characters from any values, but I'm not sure if that made a difference.

Because it's environment variables you are dealing with, it's best to reboot after you edit out any double quotes, and try to build again.

If this doesn't solve it, you can step through the batch files and do some poor man's debugging by putting "echo made it here" at various places until you find where the error is coming from.

Matthew Dixon
  • 89
  • 2
  • 5
3

I had the same problem.

In my case, it was not the PATH variable. The problem is TEMP or TMP, which are derived from the user name. When your user name contains a space, you should set TMP and TEMP to paths without spaces before starting to compile.

1

The CMakeError.log or CMakeOutput.log files will contain more information about this error. (You can look for vcvars64.bat)

For me, it said "The input line is too long" and "The syntax of the command is incorrect" in these files. In my case it was caused by the PATH environment variable being too long. The errors were solved after removing some unnecessary lines from PATH and rebooting.

0

I had the same problem.

In my case, it was because of incorrect autoexec in my command line. So I cleaned up corresponding entry in my registry (HKLM\Software\Microsoft\Command Processor\AutoRun) and everything started working.

If that does not help, I recommend to create new account on your PC and test it there. If everything works fine - it's probably something with your Windows profile configuration (like in my case).

0

Not necessarily a PATH problem. Apparently, if any one of the environmental variables contain a double quote (“"”), this happens.