undefined reference to Cuda functions error in linking .o file

Hi all,

I am trying to link an object file named gpu.o created after compiling gpu.cu using nvcc.
In gpu.cu, I have defined a function which I am calling from another .c file.
While compiling the .c file, I believe I am unable to link the code and i get the following errors:

…/gpu.o: In function __cudaUnregisterBinaryUtil': tmpxft_00004e8b_00000000-10_gpu.i:(.text+0x34): undefined reference to __cudaUnregisterFatBinary’
…/gpu.o: In function __itexfetchi': tmpxft_00004e8b_00000000-10_gpu.i:(.text+0x473d): undefined reference to __cudaTextureFetch’
…/gpu.o: In function __utexfetchi': tmpxft_00004e8b_00000000-10_gpu.i:(.text+0x4789): undefined reference to __cudaTextureFetch’
…/gpu.o: In function __ftexfetchi': tmpxft_00004e8b_00000000-10_gpu.i:(.text+0x47d5): undefined reference to __cudaTextureFetch’
…/gpu.o: In function __itexfetch': tmpxft_00004e8b_00000000-10_gpu.i:(.text+0x4821): undefined reference to __cudaTextureFetch’
…/gpu.o: In function __utexfetch': tmpxft_00004e8b_00000000-10_gpu.i:(.text+0x486d): undefined reference to __cudaTextureFetch’
…/gpu.o:tmpxft_00004e8b_00000000-10_gpu.i:(.text+0x48b9): more undefined references to __cudaTextureFetch' follow ../gpu.o: In function __sti____cudaRegisterAll_38_tmpxft_00004e8b_00000000_4_gpu_cpp1_ii_2277eae9’:
tmpxft_00004e8b_00000000-10_gpu.i:(.text+0x997e): undefined reference to `__cudaRegisterFatBinary’

Please suggest how I can remove these errors. Any suggestion is highly appreciated.

Cheers !!!

Add -lcuda to your linker command.

1 Like

Thanks tmurray,

I tried including -lcuda and I still get the same errors.

:( It Didn’t work…

Help!

You also need -lcudart

Thanks alot…

Its working

Adding both the flags helped.

:) :)

Cheers!