undefined reference to 'cuInit' when linking undefined reference to 'cuInit'

I’m getting “undefined reference to ‘cuInit’” when i try to link my code. I need to run cuInit to initialize the card, ofcourse, and i have #include “cuda.h” in the .cu file, but it still can’t find it. What am I missing?

nvcc *.o -o main

gpu_code.o in function ‘init’:
…: undefined reference to ‘cuInit’
collect2: ld returned 1 exit status

When i remove cuInit(0); from my code it links fine, but ofcourse it doesn’t work. So all I need is to get this one function call to work.


Have you tried adding -lcuda to the command? (just trying all the obvious solutions first)


thanks, that worked. now my device code doesn’t seem to be executing (although no errors are being reported anywhere, and device query works) but thats or another thread.