VS2010 Can't compile with --keep nvcc option.

I’m trying to use Visual Studio 2010 with CUDA 4.0RC2. My application compiles fine but when I try to use --keep options both in additional command line parameter or build properties it produces compile error:

1>Release/gpu.cudafe1.stub.c(1): fatal error C1083: Cannot open include file: 'Release/gpu.cudafe1.stub.c': No such file or directory

The file gpu.cudafe1.stub.c does exists in Release directory. The command line is:

cl -D__CUDA_ARCH__=200 -nologo -E -TP -DCUDA_DOUBLE_MATH_FUNCTIONS   /EHsc /nologo /Ox /Zi  /MD  -D__CUDA_PREC_DIV -D__CUDA_PREC_SQRT -I"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v4.0/include" "-IC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\bin/../include" "-IC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\bin/../include/cudart"   > "Release/gpu.cu.cpp" "Release/gpu.cudafe1.cpp"

I played with this command in cmd.exe and found out that the error goes away if -I. option is added. After that my program compiles if --keep is set in build properties but still fails when --keep is set in additional command line parameters:

LINK : warning LNK4044: unrecognized option '/-keep'; ignored

...

1>MSVCRT.lib(crtexe.obj) : error LNK2001: unresolved external symbol _main

The same happens if I try to add any other options. I think that nvcc driver shouldn’t pass his options to the linker.

I’m having some problems regarding CUDA 4.0 RC2 and VS2010, have you tested CUDA 3.2 in order to check for the same errors?

That is exactly what I’m going to do as soon as the downloads of nsight and visual studio finishes.

CUDA 3.2 (officially) doesn’t work with VS2010.

Changing the platform toolset to vc90 makes VS2010 use VS2008 compiler.

But I have VS2008 too.

I’m having a similar issue using VS2010, Cuda 4.0 RC2. As soon as I select the Cuda “Keep” option the compilation starts failing:

x64/Debug/kernel_v3.cudafe1.stub.c(1): fatal error C1083: Cannot open include file: ‘x64/Debug/kernel_v3.cudafe1.stub.c’: No such file or directory

Its failing to locate the following include file

include “crt/host_runtime.h”

Here’s the NVCC command:

C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizations\CUDA 4.0.targets(285,3): error MSB3721: The command ““C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\bin\nvcc.exe” -gencode=arch=compute_10,code="sm_10,compute_10" --use-local-env --cl-version 2010 -ccbin “C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\x86_amd64” -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\include” -G0 --keep --keep-dir “x64\Debug” -maxrregcount=0 --ptxas-options=-v --machine 64 --compile -l --verbose -D_NEXUS_DEBUG -g -Xcompiler “/EHsc /nologo /Od /Zi /MDd /GR” -o “x64\Debug\kernel_v3.cu.obj” “e:\documents\visual studio 2010\Projects\CudaTestVS2010\CudaTestVS2010\kernel_v3.cu”" exited with code 2.

This line -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\include" should ensure the include file is found in the “crt” subdirectory.

Here’s the last compiler command

1> #$ cl -D__CUDA_ARCH__=100 -nologo -E -TP -DCUDA_NO_SM_12_ATOMIC_INTRINSICS -DCUDA_NO_SM_13_DOUBLE_INTRINSICS -DCUDA_FLOAT_MATH_FUNCTIONS -DCUDA_NO_SM_11_ATOMIC_INTRINSICS /EHsc /nologo /Od /Zi /MDd /GR -D__CUDA_FTZ -I"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v4.0/include" “-IC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\bin/…/include” “-IC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\bin/…/include/cudart” > “x64/Debug/kernel_v3.cu.cpp” “x64/Debug/kernel_v3.cudafe1.cpp”

These options look wrong:

“-IC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\bin/…/include” “-IC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\bin/…/include/cudart”

But this line should still enable the “crt/host_runtime.h” to be found.

-I"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v4.0/include"

Any ideas?

The reason I’m trying to use the nvcc -keep option is so I can debug the Cuda kernel in Visual Studio. Currently VS is reporting it is unable to find the device compiled stub and is only able to show the disassembled code which makes debugging the kernel a real pain!!!

fyi, I am running VS 2010 with the V4.0 RC2 compiler and am getting the same error. (bandwidthTest)

1>bandwidthTest.cu.obj : error LNK2001: unresolved external symbol “__declspec(dllimport) __int64 const std::_BADOFF” (_imp?_BADOFF@std@@3_JB)
1>shrUtils64D.lib(shrUtils.obj) : error LNK2001: unresolved external symbol “__declspec(dllimport) __int64 const std::_BADOFF” (_imp?_BADOFF@std@@3_JB)

cs0amc, have you tried to add “-I.” option (i.e. add “.” to additional include directories)?
sumsetquest, your error looks completly different.