1

In short, when I try to compile a VS2008 project inside the IDE, it fails, but when I use the same command line on command prompt, it compiles. Can anybody help?

Details

Using VS2008 with Cuda toolkit 3.2. Also have VS2010 installed. Did the following: steps before starting the procedure.

  1. Added a custom rule file, which was in: C:\Program Files (x86)\NVIDIA GPU Computing Toolkit\CUDA\v3.2\extras\visual_studio_integration\rules
  2. Then added C:\Program Files (x86)\NVIDIA GPU Computing Toolkit\CUDA\v3.2\lib\x64 to additional library directories in linker->general in project's properties and cudart.lib and cuda.lib to additional dependencies.

Please let me know if I'm missing something.

The output of set command on cmd prompt is:

CUDA_BIN_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v3.2\\bin
CUDA_INC_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v3.2\\include
CUDA_LIB_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v3.2\\lib\x64
CUDA_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v3.2\
CUDA_PATH_V3_2=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v3.2\

Oops, forgot the error messages.

1>t.cu.obj : error LNK2019: unresolved external symbol ___cudaUnregisterFatBinary@4 referenced in function "void __cdecl __cudaUnregisterBinaryUtil(void)" (?__cudaUnregisterBinaryUtil@@YAXXZ)
1>t.cu.obj : error LNK2019: unresolved external symbol _cudaLaunch@4 referenced in function "enum cudaError __cdecl cudaLaunch<char>(char *)" (??$cudaLaunch@D@@YA?AW4cudaError@@PAD@Z)
1>t.cu.obj : error LNK2019: unresolved external symbol _cudaSetupArgument@12 referenced in function "void __cdecl __device_stub__Z12compute_sum4P6float4S0_S0_i(struct float4 *,struct float4 *,struct float4 *,int)" (?__device_stub__Z12compute_sum4P6float4S0_S0_i@@YAXPAUfloat4@@00H@Z)
1>t.cu.obj : error LNK2019: unresolved external symbol ___cudaRegisterFunction@40 referenced in function "void __cdecl __sti____cudaRegisterAll_47_tmpxft_00000ea8_00000000_8_t_compute_10_cpp1_ii_65ce9b46(void)" (?__sti____cudaRegisterAll_47_tmpxft_00000ea8_00000000_8_t_compute_10_cpp1_ii_65ce9b46@@YAXXZ)
1>t.cu.obj : error LNK2019: unresolved external symbol ___cudaRegisterFatBinary@4 referenced in function "void __cdecl __sti____cudaRegisterAll_47_tmpxft_00000ea8_00000000_8_t_compute_10_cpp1_ii_65ce9b46(void)" (?__sti____cudaRegisterAll_47_tmpxft_00000ea8_00000000_8_t_compute_10_cpp1_ii_65ce9b46@@YAXXZ)
1>t.cu.obj : error LNK2019: unresolved external symbol _cudaEventDestroy@4 referenced in function _main
1>t.cu.obj : error LNK2019: unresolved external symbol _cudaEventElapsedTime@12 referenced in function _main
1>t.cu.obj : error LNK2019: unresolved external symbol _cudaEventSynchronize@4 referenced in function _main
1>t.cu.obj : error LNK2019: unresolved external symbol _cudaConfigureCall@32 referenced in function _main
1>t.cu.obj : error LNK2019: unresolved external symbol _cudaEventRecord@8 referenced in function _main
1>t.cu.obj : error LNK2019: unresolved external symbol _cudaThreadSynchronize@0 referenced in function _main
1>t.cu.obj : error LNK2019: unresolved external symbol _cudaEventCreate@4 referenced in function _main
1>t.cu.obj : error LNK2019: unresolved external symbol _cudaMemcpy@16 referenced in function _main
1>t.cu.obj : error LNK2019: unresolved external symbol _cudaMalloc@8 referenced in function _main
1>D:\projects\cup1\Debug\cup1.exe : fatal error LNK1120: 14 unresolved externals

This is the command line:

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v3.2\\bin\nvcc.exe"    -gencode=arch=compute_10,code=\"sm_10,compute_10\" -gencode=arch=compute_20,code=\"sm_20,compute_20\"  --machine 32 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin"    -Xcompiler "/EHsc /W3 /nologo /O2 /Zi   /MT  "  -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v3.2\\include" -maxrregcount=32  --compile -o "Debug/t.cu.obj" t.cu 
Community
  • 1
  • 1
0fnt
  • 8,211
  • 9
  • 45
  • 62

3 Answers3

3

nvcc is not only a compiler but can be also used for linking.

However, when you work in VS2008, the linking stage is performed by VS. You have to tell it to include additional cuda library files.

In your project properties set:

  • Configuration Properties -> Linker -> General. Set: "Additional Library Directories" to include CUDA lib directory. Value $(CUDA_LIB_PATH) should suffice in your case, as this environment variable points in the correct direction

  • Configuration Properties -> Linker -> Input. Set: "Additional Dependencies" to "cudart.lib"

CygnusX1
  • 20,968
  • 5
  • 65
  • 109
3

You are compiling with nvcc for 32bit (--machine 32) but your linked cuda libs are 64bit ([..]\lib\x64).

LumpN
  • 46
  • 1
0

Make sure about two things:

  1. You've added cudart.lib in Additional Inputs.

  2. The path to cudart.lib and cudartxx_xx_x.dll is set in VC++ directories. Also add the path of cuda dll into your system's environment variables.

Here's a step by step guide: Run CUDA on Visual Studio 2008

jwdmsd
  • 2,107
  • 2
  • 16
  • 30