Error while building with CUDA and OPTIX

Whenever trying to build with CUDA and OPTIX I get this error and the build fails :

Generating filter_sm_30.cubin
nvcc fatal : Could not set up the environment for Microsoft Visual Studio using ‘C:/Program Files (x86)/Microsoft V
isual Studio/2019/Community/VC/Tools/MSVC/14.20.27508/bin/HostX64/x64/…/…/…/…/…/…/…/VC/Auxiliary/Build/vcvars
64.bat’
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(20
9,5): error MSB6006: “cmd.exe” exited with code 1. [C:\blender-git\build_windows_Release_x64_vc16_Release\intern\cycles
\kernel\cycles_kernel_cuda.vcxproj]
Generating kernel_optix.ptx
nvcc fatal : Could not set up the environment for Microsoft Visual Studio using ‘C:/Program Files (x86)/Microsoft V
isual Studio/2019/Community/VC/Tools/MSVC/14.20.27508/bin/HostX64/x64/…/…/…/…/…/…/…/VC/Auxiliary/Build/vcvars
64.bat’
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(20
9,5): error MSB6006: “cmd.exe” exited with code 1. [C:\blender-git\build_windows_Release_x64_vc16_Release\intern\cycles
\kernel\cycles_kernel_optix.vcxproj]

does your path environment variable contain quotes by any chance?

They don’t.

In the start menu there should be a link for Developer command prompt for VS [your version] when you start that, does it have issues?

The cmd prompt opens OK as well.

no idea then, something in your environment is wonky, and i’m not sure what it is, so we end up on the heh werid, try X? pile of ideas.

tried a fresh build folder yet?

I tried with a fresh build folder…about a dozen times already…:sweat_smile:
I also tried reinstalling Visual Studio.
The version of Cuda Toolkit is 10.2.89

funny question are there really 3 dots there?

C:/Program Files (x86)/Microsoft Visual tudio/2019/Community/VC/Tools/MSVC/14.20.27508/bin/HostX64/x64/…/…/…/…/…/…/…/VC/Auxiliary/Build/vcvars64.bat

It migth be worth double checking for quotes based on this:

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.

There are actually 2 dots but don’t know why it’s showing 3.
The issue only occurs when building with CUDA. I have successfully built blender without it in the past.

And just to be sure, when you start the developer prompt , there is no error and you can run cl --version successfully?

edit: replied to the wrong message, sorry about that.

This is the output:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community>cl --version
Microsoft ® C/C++ Optimizing Compiler Version 19.20.27508.1 for x86
Copyright © Microsoft Corporation. All rights reserved.

cl : Command line warning D9002 : ignoring unknown option ‘–version’
cl : Command line error D8003 : missing source filename

Yup that looks good, it sure doesn’t seem like a quotes in path issue, the list of ideas what could be wrong is pretty barren though…

can you check

C:/Program Files (x86)/Microsoft Visual tudio/2019/Community/VC/Auxiliary/Build/vcvars64.bat

exists? and uhh lets pick at the path a little more on a cmd.exe console, what is the output of

set path

perhaps there’s something else wonky in there?

vcvars4.bat does exist but it only contains this:

@call “%~dp0vcvarsall.bat” x64 %*

vcvarsall.bat contains:

@if not “%VSCMD_DEBUG%” GEQ “3” echo off

@REM -------------------------------------------------------------------------
:parse_args
set __VCVARSALL_STORE=
set __VCVARSALL_WINSDK=
set __VCVARSALL_PARSE_ERROR=
set __VCVARSALL_TARGET_ARCH=
set __VCVARSALL_HOST_ARCH=
set __VCVARSALL_VER=

@REM Parse command line arguments. This implementation does not care about
@REM argument order.

if “%VSCMD_DEBUG%” GEQ “1” (
@echo [DEBUG:%~nx0] init with arguments ‘%*’
)

set __VCVARSALL_PARSE_ERROR=0
set “__VCVARSALL_ARGS_LIST=%*”
call :parse_loop
set __VCVARSALL_ARGS_LIST=

if “%VSCMD_DEBUG%” GEQ “1” (
@echo [DEBUG:%~nx0] Command line parse completed with values:
@echo [DEBUG:%~nx0] __VCVARSALL_TARGET_ARCH=’%__VCVARSALL_TARGET_ARCH%’
@echo [DEBUG:%~nx0] __VCVARSALL_HOST_ARCH=’%__VCVARSALL_HOST_ARCH%’
@echo [DEBUG:%~nx0] __VCVARSALL_WINSDK=’%__VCVARSALL_WINSDK%’
@echo [DEBUG:%~nx0] __VCVARSALL_STORE=’%__VCVARSALL_STORE%’
@echo [DEBUG:%~nx0] __VCVARSALL_HELP=’%__VCVARSALL_HELP%’
@echo [DEBUG:%~nx0] __VCVARSALL_PARSE_ERROR=’%__VCVARSALL_PARSE_ERROR%’
)

if “%__VCVARSALL_CLEAN_ENV%” NEQ “” goto :call_vsdevcmd
if “%__VCVARSALL_PARSE_ERROR%” NEQ “0” goto :usage_error
if “%__VCVARSALL_HELP%” NEQ “” goto :usage

@REM -------------------------------------------------------------------------
:check_platform
@REM This script is installed to …\VC\Auxiliary\Build.
@REM vsdevcmd is installed to …\Common7\Tools.
if not exist “%~dp0…\Common7\Tools\vsdevcmd.bat” goto missing

@REM Assemble the arguments to pass to vsdevcmd.bat
if “%__VCVARSALL_TARGET_ARCH%” == “” goto :usage_error
if “%__VCVARSALL_HOST_ARCH%” == “” goto :usage_error

set “__VCVARSALL_VSDEVCMD_ARGS=-arch=%__VCVARSALL_TARGET_ARCH% -host_arch=%__VCVARSALL_HOST_ARCH%”
if “%__VCVARSALL_WINSDK%” NEQ “” (
set “__VCVARSALL_VSDEVCMD_ARGS=%__VCVARSALL_VSDEVCMD_ARGS% -winsdk=%__VCVARSALL_WINSDK%”
)
if “%__VCVARSALL_STORE%” NEQ “” (
set “__VCVARSALL_VSDEVCMD_ARGS=%__VCVARSALL_VSDEVCMD_ARGS% -app_platform=UWP”
)
if “%__VCVARSALL_VER%” NEQ “” (
set “__VCVARSALL_VSDEVCMD_ARGS=%__VCVARSALL_VSDEVCMD_ARGS% -vcvars_ver=%__VCVARSALL_VER%”
)
if “%__VCVARSALL_SPECTRE%” NEQ “” (
set “__VCVARSALL_VSDEVCMD_ARGS=%__VCVARSALL_VSDEVCMD_ARGS% -vcvars_spectre_libs=%__VCVARSALL_SPECTRE%”
)

goto :call_vsdevcmd

@REM -------------------------------------------------------------------------
@REM Call vsdevcmd.bat to setup the command prompt environment

:call_vsdevcmd

@REM This temporary environment variable is used to control setting of VC++
@REM command prompt-specific environment variables that should not be set
@REM by the VS Developer Command prompt (specifically vsdevcmd\ext\vcvars.bat).
@REM The known case this effects is the Platform environment variable, which
@REM will override platform target for .NET builds.
set VSCMD_VCVARSALL_INIT=1

@REM Special handling for the /clean_env argument
if “%__VCVARSALL_CLEAN_ENV%” NEQ “” (
call “%~dp0…\Common7\Tools\vsdevcmd.bat” /clean_env
goto :end
)

call “%~dp0…\Common7\Tools\vsdevcmd.bat” %__VCVARSALL_VSDEVCMD_ARGS%

if “%ERRORLEVEL%”==“0” (
@REM Print the target command prompt architecture…
if “%__VCVARSALL_HOST_ARCH%” NEQ “%__VCVARSALL_TARGET_ARCH%” (
echo [%~nx0] Environment initialized for: ‘%__VCVARSALL_HOST_ARCH%_%__VCVARSALL_TARGET_ARCH%’
) else (
echo [%~nx0] Environment initialized for: ‘%__VCVARSALL_TARGET_ARCH%’
)
)
goto :end

:parse_loop
for /F “tokens=1,* delims= " %%a in (”%__VCVARSALL_ARGS_LIST%") do (
if “%VSCMD_DEBUG%” GEQ “2” (
@echo [DEBUG:%~nx0] inner argument {%%a}
)
call :parse_argument %%a
set “__VCVARSALL_ARGS_LIST=%%b”
goto :parse_loop
)

exit /B 0

:parse_argument

@REM called by :parse_loop and expects the arguments to either be:
@REM 1. a single argument in %1
@REM 2. an argument pair from the command line specified as ‘%1=%2’

set __local_ARG_FOUND=
@REM Architecture
if /I “%1”==“x86” (
set __VCVARSALL_TARGET_ARCH=x86
set __VCVARSALL_HOST_ARCH=x86
set __local_ARG_FOUND=1
)
if /I “%1”==“x86_amd64” (
set __VCVARSALL_TARGET_ARCH=x64
set __VCVARSALL_HOST_ARCH=x86
set __local_ARG_FOUND=1
)
if /I “%1”==“x86_x64” (
set __VCVARSALL_TARGET_ARCH=x64
set __VCVARSALL_HOST_ARCH=x86
set __local_ARG_FOUND=1
)
if /I “%1”==“x86_arm” (
set __VCVARSALL_TARGET_ARCH=arm
set __VCVARSALL_HOST_ARCH=x86
set __local_ARG_FOUND=1
)
if /I “%1”==“x86_arm64” (
set __VCVARSALL_TARGET_ARCH=arm64
set __VCVARSALL_HOST_ARCH=x86
set __local_ARG_FOUND=1
)
if /I “%1”==“amd64” (
set __VCVARSALL_TARGET_ARCH=x64
set __VCVARSALL_HOST_ARCH=x64
set __local_ARG_FOUND=1
)
if /I “%1”==“x64” (
set __VCVARSALL_TARGET_ARCH=x64
set __VCVARSALL_HOST_ARCH=x64
set __local_ARG_FOUND=1
)
if /I “%1”==“amd64_x86” (
set __VCVARSALL_TARGET_ARCH=x86
set __VCVARSALL_HOST_ARCH=x64
set __local_ARG_FOUND=1
)
if /I “%1”==“x64_x86” (
set __VCVARSALL_TARGET_ARCH=x86
set __VCVARSALL_HOST_ARCH=x64
set __local_ARG_FOUND=1
)
if /I “%1”==“amd64_arm” (
set __VCVARSALL_TARGET_ARCH=arm
set __VCVARSALL_HOST_ARCH=x64
set __local_ARG_FOUND=1
)
if /I “%1”==“x64_arm” (
set __VCVARSALL_TARGET_ARCH=arm
set __VCVARSALL_HOST_ARCH=x64
set __local_ARG_FOUND=1
)
if /I “%1”==“amd64_arm64” (
set __VCVARSALL_TARGET_ARCH=arm64
set __VCVARSALL_HOST_ARCH=x64
set __local_ARG_FOUND=1
)
if /I “%1”==“x64_arm64” (
set __VCVARSALL_TARGET_ARCH=arm64
set __VCVARSALL_HOST_ARCH=x64
set __local_ARG_FOUND=1
)
if /I “%1”=="-vcvars_ver" (
set “__VCVARSALL_VER=%2”
set __local_ARG_FOUND=1
)
if /I “%1”=="/vcvars_ver" (
set “__VCVARSALL_VER=%2”
set __local_ARG_FOUND=1
)
if /I “%1”=="–vcvars_ver" (
set “__vcvarsall_ver=%2”
set __local_ARG_FOUND=1
)
if /I “%1”=="-vcvars_spectre_libs" (
set “__VCVARSALL_SPECTRE=%2”
set __local_ARG_FOUND=1
)
if /I “%1”=="/vcvars_spectre_libs" (
set “__VCVARSALL_SPECTRE=%2”
set __local_ARG_FOUND=1
)
if /I “%1”=="–vcvars_spectre_libs" (
set “__vcvarsall_SPECTRE=%2”
set __local_ARG_FOUND=1
)
if /I “%1”==“help” (
set __VCVARSALL_HELP=1
set __local_ARG_FOUND=1
)
if /I “%1”=="/help" (
set __VCVARSALL_HELP=1
set __local_ARG_FOUND=1
)
if /I “%1”=="-help" (
set __VCVARSALL_HELP=1
set __local_ARG_FOUND=1
)
if /I “%1”=="/?" (
set __VCVARSALL_HELP=1
set __local_ARG_FOUND=1
)
if /I “%1”=="-?" (
set __VCVARSALL_HELP=1
set __local_ARG_FOUND=1
)

@REM – /clean_env –
@REM Mostly used for internal testing to restore the state of
@REM the command line environment to its state prior to vcvarsall.bat
@REM being executed.
if /I “%1”=="/clean_env" (
set __VCVARSALL_CLEAN_ENV=/clean_env
set __local_ARG_FOUND=1
)
if /I “%1”=="-clean_env" (
set __VCVARSALL_CLEAN_ENV=/clean_env
set __local_ARG_FOUND=1
)

@REM Windows SDK Version
if /I “%1”==“8.1” (
set “__VCVARSALL_WINSDK=8.1”
set __local_ARG_FOUND=1
)

set __temp1=%1
if /I “%__temp1:~0,3%”==“10.” (
set “__VCVARSALL_WINSDK=%1”
set __local_ARG_FOUND=1
)
set __temp1=

@REM Store/UWP
if /I “%1”==“store” (
set “__VCVARSALL_STORE=-app_platform=UWP”
set __local_ARG_FOUND=1
)
if /I “%1”==“uwp” (
set “__VCVARSALL_STORE=-app_platform=UWP”
set __local_ARG_FOUND=1
)

if “%__local_ARG_FOUND%” NEQ “1” (
set /A __VCVARSALL_PARSE_ERROR=__VCVARSALL_PARSE_ERROR+1
if “%2”=="" (
@echo [ERROR:%~nx0] Invalid argument found : %1
) else (
@echo [ERROR:%~nx0] Invalid argument found : %1=%2
)
)
set __local_ARG_FOUND=
exit /B 0

:usage_error
echo [ERROR:%~nx0] Error in script usage. The correct usage is:
goto :usage

:usage
echo Syntax:
echo %~nx0 [arch] [platform_type] [winsdk_version] [-vcvars_ver=vc_version] [-vcvars_spectre_libs=spectre_mode]
echo where :
echo [arch]: x86 ^| amd64 ^| x86_amd64 ^| x86_arm ^| x86_arm64 ^| amd64_x86 ^| amd64_arm ^| amd64_arm64
echo [platform_type]: {empty} ^| store ^| uwp
echo [winsdk_version] : full Windows 10 SDK number (e.g. 10.0.10240.0) or “8.1” to use the Windows 8.1 SDK.
echo [vc_version] : {none} for default VS 2017 VC++ compiler toolset ^|
echo “14.0” for VC++ 2015 Compiler Toolset ^|
echo “14.1x” for the latest 14.1x.yyyyy toolset installed (e.g. “14.11”) ^|
echo “14.1x.yyyyy” for a specific full version number (e.g. 14.11.25503)
echo [spectre_mode] : {none} for default VS 2017 libraries without spectre mitigations ^|
echo “spectre” for VS 2017 libraries with spectre mitigations
echo:
echo The store parameter sets environment variables to support Universal Windows Platform application
echo development and is an alias for ‘uwp’.
echo:
echo For example:
echo %~nx0 x86_amd64
echo %~nx0 x86_amd64 10.0.10240.0
echo %~nx0 x86_arm uwp 10.0.10240.0
echo %~nx0 x86_arm onecore 10.0.10240.0 -vcvars_ver=14.0
echo %~nx0 x64 8.1
echo %~nx0 x64 store 8.1
echo:
echo Please make sure either Visual Studio or C++ Build SKU is installed.
goto :end

:missing
echo The specified configuration type is missing. The tools for the
echo configuration might not be installed.
goto :end

:end
set __VCVARSALL_TARGET_ARCH=
set __VCVARSALL_HOST_ARCH=
set __VCVARSALL_STORE=
set __VCVARSALL_WINSDK=
set __VCVARSALL_PARSE_ERROR=
set __VCVARSALL_CLEAN_ENV=
set VSCMD_VCVARSALL_INIT=
set __VCVARSALL_VSDEVCMD_ARGS=
set __VCVARSALL_HELP=
set __VCVARSALL_VER=
set __VCVARSALL_SPECTRE=

The output of the set path:

Path=;;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files (x86)\Intel\Intel® Management Engine Components\DAL;C:\Program Files\Intel\Intel® Management Engine Components\DAL;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\Git\cmd;C:\Program Files\TortoiseSVN\bin;C:\Program Files\TortoiseGit\bin;C:\Program Files\SlikSvn\bin;C:\Program Files\dotnet;C:\Program Files\Microsoft SQL Server\130\Tools\Binn;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Users\Acer\AppData\Local\Programs\Python\Python38-32\Scripts;C:\Users\Acer\AppData\Local\Programs\Python\Python38-32;C:\Users\Acer\AppData\Local\Microsoft\WindowsApps;C:\Users\Acer\AppData\Local\Programs\Microsoft VS Code\bin;C:\Program Files\CMake\bin;C:\Users\Acer.dotnet\tools;C:\Users\Acer\AppData\Local\GitHubDesktop\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\libnvvp;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build;
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

grasping at straws here, perhaps it’s the ® in intels directory name? try removing those entries temporarily

I’ve installed CUDA without Visual Studio Integration as the installation is failing with that. Could that be the cause?

The integration is not required, however the fact that the installation is failing may point to a common root cause, but i have honestly no idea what that may be

Fixing this is beyond me. I’ve given up.