Undefined reference to function if no link to cuRAND

Hi all,

I’m having a weird error when compiling my C++ program. I previously needed cuRAND and was compiling the program as follows:

pgcpp ... -L/usr/local/cuda-6.5/lib64/  -lcurand ...

I removed any use of cuRAND from my program, and therefore removed the -L/usr/local/cuda-6.5/lib64/ -lcurand from the compilation command above. However, I now get:

main.o: In function `main__FPCdN51dN27iiiiPdPdPdPfPiPdPd':
/.../main.cpp:35: undefined reference to `clock_gettime'

I suspect a linking problem but don’t understand how clock_gettime has any relation to the cuRAND library. If I leave -L/usr/local/cuda-6.5/lib64/ -lcuRAND, the program compiles and run fines (even without any actual use of cuRAND).

Why am I getting this error?


For these timer routines, you need to add the “-lrt”, Real Time, library to the link. The reason why it works with cuRand is because the curand shared object has a dependency to the RT shared object, so it’s implicitly linked.

Hope this helps,