Please help with CUDA compilation on linux

I have been trying to compile my first CUDA code but I have been having a hard time with nvcc include libraries etc.
So here’s what I do:

nvcc -I /usr/local/apps/cuda/3.1/cuda/include/

Since I am working from my university, I do not have permissions to copy my cuda code to the include directory. Pls kindly tell me what I should be doing. Also, I got undefined references error when I tried compiling it elsewhere.
Pls help.

I have attached my code.

Thanks. (3.96 KB)

Did you check if your $PATH and $LD_LIBRARY_PATH environment variables are set correctly?

Under my system, it’s OK. It can be compiled and run. What’s your problem? Can you give any error information?

By the way, you should include cuda.h

Maybe it’s better to compile this way:

nvcc -I/usr/local/apps/cuda/3.1/cuda/include/ -L/usr/local/apps/cuda/3.1/cuda/lib -lcuda -lcudart