I am using Visual Studio 2017 and CUDA 11.3. I am building for Windows 64-bit.
My “CUDA C/C++” ‘CUDA Runtime’ setting is at the default “Static CUDA runtime library (-cudart static)”.
However, when I look at the linker Command Line, it is showing “cudart.lib” instead of “cudart_static.lib”.
I can see the compile options are correct, but I cannot get it to link with proper lib.
When I use Microsoft’s depends.exe on my final DLL, it shows that it needs the CUDA DLL. Further proof that the DLL is needed: when I install my DLL on a PC without the toolkit it fails because it cannot find the CUDA DLL.
As a test, in ‘C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.3\lib\x64’ folder, I made a copy of cudart_static.lib and called it cudart.lib. With that, depends.exe properly shows that no CUDA DLL is needed. My DLL runs ok.
I did a search, but couldn’t find an answer to my issue.
Hi dear customer ,
Could you please file us a ticket following the instruction here Getting Help with CUDA NVCC Compiler
In case others find this. I was able to find a workaround, for now.
In your Project Properties, expand ‘Linker’ and go to ‘Input’ section. Under ‘Additional Dependencies’ put cudart_static.lib as the first lib in the list. It must be before %(AdditionalDependencies), so it is on the linker line before the cudart.lib that the CUDA Toolkit .props file adds. With cudart_static before cudart, the linker will use the methods in cudart_static. Checking my DLL with Depends confirms this and it also now works on PCs without the Toolkit installed.
Since the documentation says that the default is static, I do not know why the .props has cudart if the default is supposed to be static; it should have cudart_static. Hopefully there will be a fix from NVIDIA coming.
Your workaround is right . The current link implementation in VS specifies a CUDA runtime library directly overrides the option if the host linker resolves left to right as you found in Linker| Input . This makes -cudart option doesn’t work well . We will consider an improvement and will keep you posted in the ticket comments .