menu

hjk41的日志

Avatar

CUDA-GDB error: undefined reference to '$gpu_registers'

I encountered this problem when I was trying to compile MARS with -G option.

I first tried to copy the ptxvars.cu to the project directory, and compile it with the project files. But the compiler complained about conflicting declarations of threadIdx, etc.

I then tried to compile a simple .cu file with -G, and it worked all right. So I figured there must be something wrong with my Makefile. When I compiled the .cu file, I just used "nvcc test.cu -G", while the files in my projects was first compiled into .o files and then linked together. Then I compiled test.cu into test.o, and then tried to use "nvcc test.o" to generate the executable. Then the error message "undefined reference to ..." appeared. Suddenly I realized that the difference between the two approaches was that nvcc was not passed the -G option when linking. So I tried "nvcc test.o -G", and it worked perfectly. By adding the -G option to my link command in Makefile, I have successfully built my project.

So, remember, when you use -G to compile .cu files, also add -G to the link command line.

评论已关闭