[ 97%] Building CXX object samples/gpu/CMakeFiles/example_gpu_opengl.dir/opengl.cpp.o
Linking CXX executable ../../bin/gpu-example-opengl
CMakeFiles/example_gpu_opengl.dir/opengl.cpp.o: In function `draw(void*)':
opengl.cpp:(.text._Z4drawPv+0x21): undefined reference to `glRotated'
CMakeFiles/example_gpu_opengl.dir/opengl.cpp.o: In function `main':
opengl.cpp:(.text.startup.main+0x4ae): undefined reference to `glMatrixMode'
opengl.cpp:(.text.startup.main+0x4b3): undefined reference to `glLoadIdentity'
opengl.cpp:(.text.startup.main+0x4d8): undefined reference to `gluPerspective'
opengl.cpp:(.text.startup.main+0x4e2): undefined reference to `glMatrixMode'
opengl.cpp:(.text.startup.main+0x4e7): undefined reference to `glLoadIdentity'
opengl.cpp:(.text.startup.main+0x519): undefined reference to `gluLookAt'
opengl.cpp:(.text.startup.main+0x523): undefined reference to `glEnable'
opengl.cpp:(.text.startup.main+0x54b): undefined reference to `glTexParameteri'
opengl.cpp:(.text.startup.main+0x55f): undefined reference to `glTexEnvi'
opengl.cpp:(.text.startup.main+0x569): undefined reference to `glDisable'
collect2: error: ld returned 1 exit status
make[2]: *** [bin/gpu-example-opengl] Error 1
make[1]: *** [samples/gpu/CMakeFiles/example_gpu_opengl.dir/all] Error 2
Hi,
got the same problem on Debian 8 with cmake 3.0.2.
My temporary solution was to add
-lGL -lGLU
toopencv-3.1.0/build/samples/gpu/CMakeFiles/example_gpu_opengl.dir/link.txt
file.For fixing the problem, one more permanent solution is to add in opencv/samples/gpu/CMakeLists.txt the following lines:
and add
${OPENGL_LIBRARIES} ${GLUT_LIBRARY}
in the related target_link_libraries.@saigowri @twmht As you might know, the CMakeLists.txt is a file that is processed by cmake to generate the Makefile, which includes all the necessary information for the compiler and the linker, including the links to the libraries. The
find_package
is a command for finding and loading settings for an external project. Basically, the variables${OPENGL_LIBRARIES} ${GLUT_LIBRARY}
are set by the relatedfind_package
.You need to specify that the project need to be linked to OpenGL and GLUT libraries. To do that, change the line 52 (at least in my version of the file) of the related CMakeLists.txt
ocv_target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${OPENCV_CUDA_SAMPLES_REQUIRED_DEPS})
with the following
ocv_target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${OPENCV_CUDA_SAMPLES_REQUIRED_DEPS} ${OPENGL_LIBRARIES} ${GLUT_LIBRARY})
Got this error too. @quattrinili suggestion helped me. Arch Linux x86-64 4.5.1.1 opencv 3.1.0 (opencv-contrib from aur actually)
I can’t find the opencv/build/samples/gpu/CMakeFiles/example_gpu_opengl.dir/link.txt directory. I’m using Ubuntu 14.04 and opencv 3.1.0. Can u help me?
Ah, the entire
link.txt
file is a single line command. Turn off Word Wrap to see that. You just need to add-lGL -lGLU
to the end of that line. Don’t add it on a new line.