2

I'm trying to compile a software that uses QtOpenGL, but I got a link error because -lGLU is not present. cmake is used. The only relevant line in CMakeLists.txt files seems to me find_package(Qt4 REQUIRED)

The system is Linux 64bit, Debian unstable, qt version 4.7.3, cmake version 2.8

rebli
  • 91
  • 2
  • 4

4 Answers4

4

GLU is neither part of OpenGL nor Qt. You must add it as an additional dependency manually; the CMake FindOpenGL module also searches for GLU

% cmake --help-module FindOpenGL
cmake version 2.8.1
  FindOpenGL
       Try to find OpenGL

       Once done this will define


         OPENGL_FOUND        - system has OpenGL
         OPENGL_XMESA_FOUND  - system has XMESA
         OPENGL_GLU_FOUND    - system has GLU
         OPENGL_INCLUDE_DIR  - the GL include directory
         OPENGL_LIBRARIES    - Link these to use OpenGL and GLU


       If you want to use just GL you can use these values

         OPENGL_gl_LIBRARY   - Path to OpenGL Library
         OPENGL_glu_LIBRARY  - Path to GLU Library


       On OSX default to using the framework version of opengl

People will have to change the cache values of OPENGL_glu_LIBRARY and OPENGL_gl_LIBRARY to use OpenGL with X11 on OSX

       Defined in: /usr/share/cmake/Modules/FindOpenGL.cmake
datenwolf
  • 159,371
  • 13
  • 185
  • 298
3

I solved it this way:

target_link_libraries(MyProgram ${QT_LIBRARIES} GL GLU glut)
Anthony
  • 12,177
  • 9
  • 69
  • 105
linello
  • 8,451
  • 18
  • 63
  • 109
  • This is not a good CMake solution, though. Whether the GL, GLU and glut libraries are available won't be tested that way. – Alexis Wilke Apr 22 '18 at 00:57
2

If you do set(QT_USE_QTOPENGL TRUE) then -lGLU is included in the linker options:

find_package(Qt4 REQUIRED)
set(QT_USE_QTOPENGL TRUE)
include(${QT_USE_FILE})
message("Libs: ${QT_LIBRARIES}")
add_executable(program main.cpp)
target_link_libraries(program ${QT_LIBRARIES})
antonakos
  • 8,261
  • 2
  • 31
  • 34
  • the following lines in CMakeLists.txt `find_package(Qt4 REQUIRED)` `set(QT_USE_QTXML 1)` `set(QT_USE_QTOPENGL 1)` `set(QT_USE_QT3SUPPORT 1)` `include(${QT_USE_FILE})` `message("Libs: ${QT_LIBRARIES}")` give `Libs: /usr/lib/libQt3Support.so;/usr/lib/libQtOpenGL.so;/usr/lib/libQtGui.so;/usr/lib/libQtXml.so;/usr/lib/libQtSql.so;/usr/lib/libQtNetwork.so;/usr/lib/libQtCore.so` – rebli Jul 25 '11 at 23:11
  • @rebli I don't think I can help any further then. The output of those lines on my system contains `-lGL` and `-lGLU`. I am also using cmake version 2.8. – antonakos Jul 26 '11 at 00:11
1

I don't know if this is the right solution, but the build completes after I added these lines to CMakeLists.txt:

find_package(OpenGL)

and added

${OPENGL_LIBRARIES}

to

target_link_libraries
Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
rebli
  • 91
  • 2
  • 4