cuda by example - glut problem undefined reference to 'glutInit' etc.

Hello,

I’m trying to compile the “julia_gpu.cu” example in the “CUDA by example” textbook and encounter the following problem:

the command “nvcc -o julia_gpu julia_gpu.cu” returns the error message

/tmp/tmpxft_00000a99_00000000-13_julia_gpu.o: In function `CPUBitmap::display_and_exit(void (*)(void*))':

tmpxft_00000a99_00000000-1_julia_gpu.cudafe1.cpp:(.text._ZN9CPUBitmap16display_and_exitEPFvPvE[CPUBitmap::display_and_exit(void (*)(void*))]+0x4e): undefined reference to `glutInit'

tmpxft_00000a99_00000000-1_julia_gpu.cudafe1.cpp:(.text._ZN9CPUBitmap16display_and_exitEPFvPvE[CPUBitmap::display_and_exit(void (*)(void*))]+0x58): undefined reference to `glutInitDisplayMode'

tmpxft_00000a99_00000000-1_julia_gpu.cudafe1.cpp:(.text._ZN9CPUBitmap16display_and_exitEPFvPvE[CPUBitmap::display_and_exit(void (*)(void*))]+0x6f): undefined reference to `glutInitWindowSize'

tmpxft_00000a99_00000000-1_julia_gpu.cudafe1.cpp:(.text._ZN9CPUBitmap16display_and_exitEPFvPvE[CPUBitmap::display_and_exit(void (*)(void*))]+0x79): undefined reference to `glutCreateWindow'

tmpxft_00000a99_00000000-1_julia_gpu.cudafe1.cpp:(.text._ZN9CPUBitmap16display_and_exitEPFvPvE[CPUBitmap::display_and_exit(void (*)(void*))]+0x83): undefined reference to `glutKeyboardFunc'

tmpxft_00000a99_00000000-1_julia_gpu.cudafe1.cpp:(.text._ZN9CPUBitmap16display_and_exitEPFvPvE[CPUBitmap::display_and_exit(void (*)(void*))]+0x8d): undefined reference to `glutDisplayFunc'

tmpxft_00000a99_00000000-1_julia_gpu.cudafe1.cpp:(.text._ZN9CPUBitmap16display_and_exitEPFvPvE[CPUBitmap::display_and_exit(void (*)(void*))]+0x92): undefined reference to `glutMainLoop'

/tmp/tmpxft_00000a99_00000000-13_julia_gpu.o: In function `CPUBitmap::Draw()':

tmpxft_00000a99_00000000-1_julia_gpu.cudafe1.cpp:(.text._ZN9CPUBitmap4DrawEv[CPUBitmap::Draw()]+0x27): undefined reference to `glClearColor'

tmpxft_00000a99_00000000-1_julia_gpu.cudafe1.cpp:(.text._ZN9CPUBitmap4DrawEv[CPUBitmap::Draw()]+0x31): undefined reference to `glClear'

tmpxft_00000a99_00000000-1_julia_gpu.cudafe1.cpp:(.text._ZN9CPUBitmap4DrawEv[CPUBitmap::Draw()]+0x5c): undefined reference to `glDrawPixels'

tmpxft_00000a99_00000000-1_julia_gpu.cudafe1.cpp:(.text._ZN9CPUBitmap4DrawEv[CPUBitmap::Draw()]+0x61): undefined reference to `glFlush'

collect2: ld returned 1 exit status

I have libglut3 installed and can locate the gl.h, glu.h, glut.h etc. in /usr/include/GL.

I also tried “nvcc -o julia_gpu julia_gpu.cu -Iglut” and “nvcc -o julia_gpu julia_gpu.cu -IGL -Iglut” but get the same error message.

Any idea on what might be the problem?

Hello,

I’m trying to compile the “julia_gpu.cu” example in the “CUDA by example” textbook and encounter the following problem:

the command “nvcc -o julia_gpu julia_gpu.cu” returns the error message

/tmp/tmpxft_00000a99_00000000-13_julia_gpu.o: In function `CPUBitmap::display_and_exit(void (*)(void*))':

tmpxft_00000a99_00000000-1_julia_gpu.cudafe1.cpp:(.text._ZN9CPUBitmap16display_and_exitEPFvPvE[CPUBitmap::display_and_exit(void (*)(void*))]+0x4e): undefined reference to `glutInit'

tmpxft_00000a99_00000000-1_julia_gpu.cudafe1.cpp:(.text._ZN9CPUBitmap16display_and_exitEPFvPvE[CPUBitmap::display_and_exit(void (*)(void*))]+0x58): undefined reference to `glutInitDisplayMode'

tmpxft_00000a99_00000000-1_julia_gpu.cudafe1.cpp:(.text._ZN9CPUBitmap16display_and_exitEPFvPvE[CPUBitmap::display_and_exit(void (*)(void*))]+0x6f): undefined reference to `glutInitWindowSize'

tmpxft_00000a99_00000000-1_julia_gpu.cudafe1.cpp:(.text._ZN9CPUBitmap16display_and_exitEPFvPvE[CPUBitmap::display_and_exit(void (*)(void*))]+0x79): undefined reference to `glutCreateWindow'

tmpxft_00000a99_00000000-1_julia_gpu.cudafe1.cpp:(.text._ZN9CPUBitmap16display_and_exitEPFvPvE[CPUBitmap::display_and_exit(void (*)(void*))]+0x83): undefined reference to `glutKeyboardFunc'

tmpxft_00000a99_00000000-1_julia_gpu.cudafe1.cpp:(.text._ZN9CPUBitmap16display_and_exitEPFvPvE[CPUBitmap::display_and_exit(void (*)(void*))]+0x8d): undefined reference to `glutDisplayFunc'

tmpxft_00000a99_00000000-1_julia_gpu.cudafe1.cpp:(.text._ZN9CPUBitmap16display_and_exitEPFvPvE[CPUBitmap::display_and_exit(void (*)(void*))]+0x92): undefined reference to `glutMainLoop'

/tmp/tmpxft_00000a99_00000000-13_julia_gpu.o: In function `CPUBitmap::Draw()':

tmpxft_00000a99_00000000-1_julia_gpu.cudafe1.cpp:(.text._ZN9CPUBitmap4DrawEv[CPUBitmap::Draw()]+0x27): undefined reference to `glClearColor'

tmpxft_00000a99_00000000-1_julia_gpu.cudafe1.cpp:(.text._ZN9CPUBitmap4DrawEv[CPUBitmap::Draw()]+0x31): undefined reference to `glClear'

tmpxft_00000a99_00000000-1_julia_gpu.cudafe1.cpp:(.text._ZN9CPUBitmap4DrawEv[CPUBitmap::Draw()]+0x5c): undefined reference to `glDrawPixels'

tmpxft_00000a99_00000000-1_julia_gpu.cudafe1.cpp:(.text._ZN9CPUBitmap4DrawEv[CPUBitmap::Draw()]+0x61): undefined reference to `glFlush'

collect2: ld returned 1 exit status

I have libglut3 installed and can locate the gl.h, glu.h, glut.h etc. in /usr/include/GL.

I also tried “nvcc -o julia_gpu julia_gpu.cu -Iglut” and “nvcc -o julia_gpu julia_gpu.cu -IGL -Iglut” but get the same error message.

Any idea on what might be the problem?

OK, figured it out… I just typed a capital i instead of a lower case l. Stupid mistake…

Thanks anyway.

OK, figured it out… I just typed a capital i instead of a lower case l. Stupid mistake…

Thanks anyway.

Just to make things clear, its supposed to be compiled as
nvcc julia_gpu.cu -lglut -lGLU -lGL

You also need to change
cuComplex( float a, float b ) : r(a), i(b) {}
to device cuComplex( float a, float b ) : r(a), i(b) {}

This is because functions that are declared as __device __ functions can only be called either from device functions or global functions.

1 Like

Thanks xen_! I was a little stuck on this too. Just out of curiosity, did you learn those flags from the book or was that discovery from somewhere else? Cheers.

Thanks xen_! Feel lucky to find the answer.
It works for me.

1 Like