Cannot use nvcc to run cuda file

Hi, all:

I am stuck in enabling nvcc to compile my cuda file.

At first, I got the mistake cannot find ‘cl.exe’

Then I fix it writing codes like

nvcc file.cu -ccbin="C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\cl.exe"

I got the error:

LINK: fatal error LNK1104:cannot open file ‘kernel32.lib’

Then I searched internet, and modify the codes like that:

nvcc file.cu -ccbin="C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\cl.exe" -L="C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib"

Now I get errors
LINK: fatal error LNK1120:79 unsolved externals

Someone please help me out. Pulling my hairs all these days.

The OS is win 7 64; I use Microsoft Visual Studio 10.0 trial, CUDA tool version is 4.0

You are forgetting to tell the compiler for where to look for the include headers for CUDA. (-I flag)

That aside, I’m confused why you’re trying to generate a command line compiling argument by yourself. Make a CUDA project Under Visual Studio… Update your CUDA if possible, as the latest CUDA 5.5 has support for up to Visual Studio 2012 and 2010.

If you don’t want to update CUDA try something like this: http://stackoverflow.com/questions/3953326/how-to-compile-cuda-app-is-visual-studio-2010

Here is an example (debug) compile command line that Visual Studio 2010 generates for the simplePrintf example under CUDA 5.0. For me, I had to run quags’ solution from here: http://stackoverflow.com/questions/2990331/ms-c-2010-and-mspdb100-dll to get it working. Michael Paulukonis’ solution probably works as well. Basically calling that vcvars32.bat batch file to set up the environment.

"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\bin\nvcc.exe" -gencode=arch=compute_35,code=\"sm_35,compute_35\" -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\include" -I"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include" -I"C:\ProgramData\NVIDIA Corporation\CUDA Samples\v5.0\common\inc" -G -maxrregcount=0 --machine 32 --compile -g -DWIN32 -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /Zi /RTC1 /MTd " "C:\ProgramData\NVIDIA Corporation\CUDA Samples\v5.0

“C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\bin\nvcc.exe” -gencode=arch=compute_35,code=“sm_35,compute_35” -ccbin “C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin” -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\include" -I"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include" -I"C:\ProgramData\NVIDIA Corporation\CUDA Samples\v5.0\common\inc" -G -maxrregcount=0 --machine 32 --compile -g -DWIN32 -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /Zi /RTC1 /MTd " “C:\ProgramData\NVIDIA Corporation\CUDA Samples\v5.0\0_Simple\simplePrintf\simplePrintf.cu”

_Simple\simplePrintf\simplePrintf.cu"

Sample (debug) link command line:

See more example (generic) compile/link command lines here:
http://www.mcs.anl.gov/research/projects/mpi/mpich1-old/docs/mpichntman/node10.htm

Edit: I tested the link command line, for completion and it works to link. The executable works as expected, as well.

Needless to say compiling via command line can be a pain and you should probably just run the compilation from VS2010 unless you really need to otherwise.