Problem:
Building projects with the Cuda tool chain in Visual Studio fails. Here an error from the default example that comes with the Cuda Toolkit:
Build started at 12:47...
1>------ Build started: Project: CudaRuntime1, Configuration: Debug x64 ------
1>Compiling CUDA source file kernel.cu...
1>
1>E:\tmp\CudaRuntime1\CudaRuntime1>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\bin\nvcc.exe" -gencode=arch=compute_75,code=\"sm_75,compute_75\" --use-local-env -ccbin "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\bin\HostX64\x64" -x cu -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\include" -G --keep-dir x64\Debug -maxrregcount=0 --machine 64 --compile -cudart static -g -DWIN32 -DWIN64 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /FS /Zi /RTC1 /MDd " -Xcompiler "/Fdx64\Debug\vc143.pdb" -o E:\tmp\CudaRuntime1\CudaRuntime1\x64\Debug\kernel.cu.obj "E:\tmp\CudaRuntime1\CudaRuntime1\kernel.cu"
1>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\BuildCustomizations\CUDA 13.0.targets(803,9): error MSB3721: The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\bin\nvcc.exe" -gencode=arch=compute_75,code=\"sm_75,compute_75\" --use-local-env -ccbin "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\bin\HostX64\x64" -x cu -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\include" -G --keep-dir x64\Debug -maxrregcount=0 --machine 64 --compile -cudart static -g -DWIN32 -DWIN64 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /FS /Zi /RTC1 /MDd " -Xcompiler "/Fdx64\Debug\vc143.pdb" -o E:\tmp\CudaRuntime1\CudaRuntime1\x64\Debug\kernel.cu.obj "E:\tmp\CudaRuntime1\CudaRuntime1\kernel.cu"" exited with code 1.
1>Done building project "CudaRuntime1.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Build completed at 12:47 and took 02.272 seconds ==========
According to the Microsoft references, the error MSB3721 is just saying that “something” went wrong. Not super helpful. There are other mentions of similar errors on both, the Microsoft and Nvidia forums, but nothing that really stood out as helpful for my problem.
Below is a section with more details and other informations that I found during the analysis of the problem. My current best working hypothesis is that something causes Visual Studio to initialize its prompt with the 32-bit toolchains (x86), not the 64-bit one (x64). Cuda is fixed on x64 and, hence, the failure.
I currently don’t have any more gradient that I can follow to debug this. It’s not a blocker as I have a work-around (running MSBUILD.exe in a x64 Native Tools Command Prompt, cf. details sections below) but it’s kind of annoying.
Did anybody else run into this? And happens to know a fix or has a suggestion for what else to check?
Repro
- [optional] Start from a clean slate:
- Remove all Visual Studio instances and run
InstallCleanup.exe(cf. Uninstall or Remove Visual Studio | Microsoft Learn ) - Remove all Cuda Toolkit
- Remove all Visual Studio instances and run
- No environment variables referring to either Visual Studio or any NVidia tools
- Up-to-date NVidia driver (581.15)
- Install Visual Studio Community (17.14.13)
- Install Cuda Toolkit (13.0)
- Open Visual Studio and
- Choose “Create a new project”
- Select template “Cuda 13.0 Runtime” (except for the code location left all other settings as-is)
- After the initialization, build the project “CudaRuntime1”
- Observe the build error
More details
Repro in Developer Command Prompt
The same error appears when building with MSBUILD.exe from inside the Developer Command Prompt of Visual Studio (Tools > Command Line > Developer Command Prompt):
**********************************************************************
** Visual Studio 2022 Developer Command Prompt v17.14.13
** Copyright (c) 2025 Microsoft Corporation
**********************************************************************
E:\tmp\CudaRuntime1>msbuild CudaRuntime1.sln
MSBuild version 17.14.19+164abd434 for .NET Framework
Build started 8/31/2025 12:48:59.
Project "E:\tmp\CudaRuntime1\CudaRuntime1.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
Building solution configuration "Debug|x64".
Project "E:\tmp\CudaRuntime1\CudaRuntime1.sln" (1) is building "E:\tmp\CudaRuntime1\CudaRuntime1\CudaRuntime1.vcxproj"
(2) on node 1 (default targets).
PrepareForBuild:
Structured output is enabled. The formatting of compiler diagnostics will reflect the error hierarchy. See https://ak
a.ms/cpp/structured-output for more details.
InitializeBuildStatus:
Touching "x64\Debug\CudaRuntime1.tlog\unsuccessfulbuild".
AddCudaCompileDeps:
Skipping target "AddCudaCompileDeps" because all output files are up-to-date with respect to the input files.
AddCudaCompilePropsDeps:
Skipping target "AddCudaCompilePropsDeps" because all output files are up-to-date with respect to the input files.
WriteCudaCompileTlogs:
Skipping target "WriteCudaCompileTlogs" because all output files are up-to-date with respect to the input files.
Project "E:\tmp\CudaRuntime1\CudaRuntime1\CudaRuntime1.vcxproj" (2) is building "E:\tmp\CudaRuntime1\CudaRuntime1\CudaR
untime1.vcxproj" (2:2) on node 1 (CudaBuildCore target(s)).
CudaBuildCore:
Compiling CUDA source file kernel.cu...
cmd.exe /C "C:\Users\Nils Plath\AppData\Local\Temp\tmp905a11ca21dc4d1e877289fec67d4a91.cmd"
"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\bin\nvcc.exe" -gencode=arch=compute_75,code=\"sm_75,compute
_75\" --use-local-env -ccbin "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\bin\H
ostX64\x64" -x cu -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\include" -I"C:\Program Files\NVIDIA G
PU Computing Toolkit\CUDA\v13.0\include" -G --keep-dir x64\Debug -maxrregcount=0 --machine 64 --compile -cudar
t static -g -DWIN32 -DWIN64 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /FS /Zi /RTC1 /MDd " -Xco
mpiler "/Fdx64\Debug\vc143.pdb" -o E:\tmp\CudaRuntime1\CudaRuntime1\x64\Debug\kernel.cu.obj "E:\tmp\CudaRuntime1\Cuda
Runtime1\kernel.cu"
E:\tmp\CudaRuntime1\CudaRuntime1>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\bin\nvcc.exe" -gencode=arc
h=compute_75,code=\"sm_75,compute_75\" --use-local-env -ccbin "C:\Program Files\Microsoft Visual Studio\2022\Communit
y\VC\Tools\MSVC\14.44.35207\bin\HostX64\x64" -x cu -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\incl
ude" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\include" -G --keep-dir x64\Debug -maxrregcount=0
--machine 64 --compile -cudart static -g -DWIN32 -DWIN64 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nol
ogo /Od /FS /Zi /RTC1 /MDd " -Xcompiler "/Fdx64\Debug\vc143.pdb" -o E:\tmp\CudaRuntime1\CudaRuntime1\x64\Debug\kernel
.cu.obj "E:\tmp\CudaRuntime1\CudaRuntime1\kernel.cu"
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\BuildCustomizations\CUDA 13.0.targets
(803,9): error MSB3721: The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\bin\nvcc.exe" -gencode=a
rch=compute_75,code=\"sm_75,compute_75\" --use-local-env -ccbin "C:\Program Files\Microsoft Visual Studio\2022\Communit
y\VC\Tools\MSVC\14.44.35207\bin\HostX64\x64" -x cu -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\includ
e" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\include" -G --keep-dir x64\Debug -maxrregcount=0
--machine 64 --compile -cudart static -g -DWIN32 -DWIN64 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /O
d /FS /Zi /RTC1 /MDd " -Xcompiler "/Fdx64\Debug\vc143.pdb" -o E:\tmp\CudaRuntime1\CudaRuntime1\x64\Debug\kernel.cu.obj
"E:\tmp\CudaRuntime1\CudaRuntime1\kernel.cu"" exited with code 1. [E:\tmp\CudaRuntime1\CudaRuntime1\CudaRuntime1.vcxpro
j]
Done Building Project "E:\tmp\CudaRuntime1\CudaRuntime1\CudaRuntime1.vcxproj" (CudaBuildCore target(s)) -- FAILED.
Done Building Project "E:\tmp\CudaRuntime1\CudaRuntime1\CudaRuntime1.vcxproj" (default targets) -- FAILED.
Done Building Project "E:\tmp\CudaRuntime1\CudaRuntime1.sln" (default targets) -- FAILED.
Build FAILED.
"E:\tmp\CudaRuntime1\CudaRuntime1.sln" (default target) (1) ->
"E:\tmp\CudaRuntime1\CudaRuntime1\CudaRuntime1.vcxproj" (default target) (2) ->
"E:\tmp\CudaRuntime1\CudaRuntime1\CudaRuntime1.vcxproj" (CudaBuildCore target) (2:2) ->
(CudaBuildCore target) ->
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\BuildCustomizations\CUDA 13.0.targe
ts(803,9): error MSB3721: The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\bin\nvcc.exe" -gencode
=arch=compute_75,code=\"sm_75,compute_75\" --use-local-env -ccbin "C:\Program Files\Microsoft Visual Studio\2022\Commun
ity\VC\Tools\MSVC\14.44.35207\bin\HostX64\x64" -x cu -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\incl
ude" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\include" -G --keep-dir x64\Debug -maxrregcount=0
--machine 64 --compile -cudart static -g -DWIN32 -DWIN64 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo
/Od /FS /Zi /RTC1 /MDd " -Xcompiler "/Fdx64\Debug\vc143.pdb" -o E:\tmp\CudaRuntime1\CudaRuntime1\x64\Debug\kernel.cu.ob
j "E:\tmp\CudaRuntime1\CudaRuntime1\kernel.cu"" exited with code 1. [E:\tmp\CudaRuntime1\CudaRuntime1\CudaRuntime1.vcxp
roj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.97
E:\tmp\CudaRuntime1>
A more detailed error message
When only executing the build command from above, the error is as follows:
E:\tmp\CudaRuntime1>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\bin\nvcc.exe" -gencode=arch=compute_75,code=\"sm_75,compute_75\" --use-local-env -ccbin "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\bin\HostX64\x64" -x cu -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\include" -G --keep-dir x64\Debug -maxrregcount=0 --machine 64 --compile -cudart static -g -DWIN32 -DWIN64 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo/Od /FS /Zi /RTC1 /MDd " -Xcompiler "/Fdx64\Debug\vc143.pdb" -o E:\tmp\CudaRuntime1\CudaRuntime1\x64\Debug\kernel.cu.obj "E:\tmp\CudaRuntime1\CudaRuntime1\kernel.cu"
nvcc fatal : cl.exe in PATH (C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/bin/HostX86/x86) is different than one specified with -ccbin (C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/bin/HostX64/x64)
E:\tmp\CudaRuntime1>
There, that’s more helpful: nvcc fatal : cl.exe in PATH ...
Checking environment variables in Developer Command Prompt
A quick check of the environment settings in the command prompt from above reveals that
Platform=x64
but
VSCMD_ARG_HOST_ARCH=x86
VSCMD_ARG_TGT_ARCH=x86
Path=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\bin\HostX86\x86;...
Huh!?! Why?
I double-checked platform settings for the Cuda project inside Visual Studio: Debug, x64! All good!
So, why does this happen?
Build works in x64 Native Tools Command Prompt
Curiously, when repeating the build with MSBUILD.exe from an x64 Native Tools Command Prompt (Windows Menu > …) it works as expected:
**********************************************************************
** Visual Studio 2022 Developer Command Prompt v17.14.13
** Copyright (c) 2025 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'
C:\Program Files\Microsoft Visual Studio\2022\Community>E:
E:\>cd tmp\CudaRuntime1
E:\tmp\CudaRuntime1>msbuild CudaRuntime1.sln
MSBuild version 17.14.19+164abd434 for .NET Framework
Build started 8/31/2025 12:50:18.
Project "E:\tmp\CudaRuntime1\CudaRuntime1.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
Building solution configuration "Debug|x64".
Project "E:\tmp\CudaRuntime1\CudaRuntime1.sln" (1) is building "E:\tmp\CudaRuntime1\CudaRuntime1\CudaRuntime1.vcxproj"
(2) on node 1 (default targets).
PrepareForBuild:
Structured output is enabled. The formatting of compiler diagnostics will reflect the error hierarchy. See https://ak
a.ms/cpp/structured-output for more details.
InitializeBuildStatus:
Touching "x64\Debug\CudaRuntime1.tlog\unsuccessfulbuild".
AddCudaCompileDeps:
Skipping target "AddCudaCompileDeps" because all output files are up-to-date with respect to the input files.
AddCudaCompilePropsDeps:
Skipping target "AddCudaCompilePropsDeps" because all output files are up-to-date with respect to the input files.
WriteCudaCompileTlogs:
Skipping target "WriteCudaCompileTlogs" because all output files are up-to-date with respect to the input files.
Project "E:\tmp\CudaRuntime1\CudaRuntime1\CudaRuntime1.vcxproj" (2) is building "E:\tmp\CudaRuntime1\CudaRuntime1\CudaR
untime1.vcxproj" (2:2) on node 1 (CudaBuildCore target(s)).
CudaBuildCore:
Compiling CUDA source file kernel.cu...
cmd.exe /C "C:\Users\Nils Plath\AppData\Local\Temp\tmp337f920378524f7e838296a8cfe70eb4.cmd"
"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\bin\nvcc.exe" -gencode=arch=compute_75,code=\"sm_75,compute
_75\" --use-local-env -ccbin "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\bin\H
ostX64\x64" -x cu -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\include" -I"C:\Program Files\NVIDIA G
PU Computing Toolkit\CUDA\v13.0\include" -G --keep-dir x64\Debug -maxrregcount=0 --machine 64 --compile -cudar
t static -g -DWIN32 -DWIN64 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /FS /Zi /RTC1 /MDd " -Xco
mpiler "/Fdx64\Debug\vc143.pdb" -o E:\tmp\CudaRuntime1\CudaRuntime1\x64\Debug\kernel.cu.obj "E:\tmp\CudaRuntime1\Cuda
Runtime1\kernel.cu"
E:\tmp\CudaRuntime1\CudaRuntime1>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\bin\nvcc.exe" -gencode=arc
h=compute_75,code=\"sm_75,compute_75\" --use-local-env -ccbin "C:\Program Files\Microsoft Visual Studio\2022\Communit
y\VC\Tools\MSVC\14.44.35207\bin\HostX64\x64" -x cu -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\incl
ude" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\include" -G --keep-dir x64\Debug -maxrregcount=0
--machine 64 --compile -cudart static -g -DWIN32 -DWIN64 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nol
ogo /Od /FS /Zi /RTC1 /MDd " -Xcompiler "/Fdx64\Debug\vc143.pdb" -o E:\tmp\CudaRuntime1\CudaRuntime1\x64\Debug\kernel
.cu.obj "E:\tmp\CudaRuntime1\CudaRuntime1\kernel.cu"
kernel.cu
tmpxft_00000eb0_00000000-7_kernel.cudafe1.cpp
Done Building Project "E:\tmp\CudaRuntime1\CudaRuntime1\CudaRuntime1.vcxproj" (CudaBuildCore target(s)).
Link:
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\bin\HostX64\x64\link.exe /ERRORREPO
RT:QUEUE /OUT:"E:\tmp\CudaRuntime1\x64\Debug\CudaRuntime1.exe" /INCREMENTAL /ILK:"x64\Debug\CudaRuntime1.ilk" /NOLOGO
/LIBPATH:"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\lib\x64" cudart_static.lib kernel32.lib user32.li
b gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.li
b kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.li
b odbc32.lib odbccp32.lib cudart.lib cudadevrt.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manif
est:embed /DEBUG /PDB:"E:\tmp\CudaRuntime1\x64\Debug\CudaRuntime1.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCO
MPAT /IMPLIB:"E:\tmp\CudaRuntime1\x64\Debug\CudaRuntime1.lib" /MACHINE:X64 E:\tmp\CudaRuntime1\CudaRuntime1\x64\Debug
\kernel.cu.obj
Creating library E:\tmp\CudaRuntime1\x64\Debug\CudaRuntime1.lib and object E:\tmp\CudaRuntime1\x64\Debug\CudaRunti
me1.exp
LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library [E:\tmp\CudaRun
time1\CudaRuntime1\CudaRuntime1.vcxproj]
CudaRuntime1.vcxproj -> E:\tmp\CudaRuntime1\x64\Debug\CudaRuntime1.exe
FinalizeBuildStatus:
Deleting file "x64\Debug\CudaRuntime1.tlog\unsuccessfulbuild".
Touching "x64\Debug\CudaRuntime1.tlog\CudaRuntime1.lastbuildstate".
Done Building Project "E:\tmp\CudaRuntime1\CudaRuntime1\CudaRuntime1.vcxproj" (default targets).
Done Building Project "E:\tmp\CudaRuntime1\CudaRuntime1.sln" (default targets).
Build succeeded.
"E:\tmp\CudaRuntime1\CudaRuntime1.sln" (default target) (1) ->
"E:\tmp\CudaRuntime1\CudaRuntime1\CudaRuntime1.vcxproj" (default target) (2) ->
(Link target) ->
LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library [E:\tmp\CudaR
untime1\CudaRuntime1\CudaRuntime1.vcxproj]
1 Warning(s)
0 Error(s)
Time Elapsed 00:00:02.28
E:\tmp\CudaRuntime1>
All of this suggests that something in the initialization of the Developer Command Prompt
Repro with other projects
The same error can be reproduced with the code from GitHub - NVIDIA/cuda-samples: Samples for CUDA Developers which demonstrates features in CUDA Toolkit
In a x64 Native Tools Command Prompt:
# Clone the repo and cd into it
mkdir build && cd build
cmake .. -G "Visual Studio 17 2022" -A x64
Let CMake do its thing, then open build\cuda-samples.sln in Visual Studio and build the solution - same error MSB3721.
However, back in the x64 Native Tools Command Prompt the following builds as expected:
msbuild cuda-samples.ln
Unsorted details
- After building the project with
MSBUILD.exein a x64 Native Tools Command Prompt, it’s possible to run and debug all executables from Visual Studio … - The same error happens with Cuda Toolkit version 12.5 and 12.6.
- I couldn’t easily find a version of Visual Studio 2019 Community, so I haven’t tried that.