Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. Opengl with cmake
Forum Update on Monday, May 27th 2025

Opengl with cmake

Scheduled Pinned Locked Moved Installation and Deployment
1 Posts 1 Posters 3.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dyeray
    wrote on 6 Jul 2012, 21:50 last edited by
    #1

    Hi, I have a problem trying to compile a small application that uses QtOpenGL with CMake. Here are the CMake files:

    @project(tracking-example)
    cmake_minimum_required(VERSION 2.8)
    find_package(Qt4 REQUIRED)
    find_package(OpenCV REQUIRED)
    add_definitions(${QT_DEFINITIONS})
    include_directories(${QT_INCLUDES})
    add_subdirectory(src)@

    and:

    @set(tracking-example_SRCS
    main.cpp
    MainWindow.cpp
    glwidget.cpp
    )
    set(QT_USE_QTOPENGL TRUE)
    INCLUDE (${QT_USE_FILE})
    qt4_wrap_cpp(tracking-example_SRCS MainWindow.h)
    add_executable(tracking-example ${tracking-example_SRCS})
    target_link_libraries(tracking-example ${OpenCV_LIBS} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_LIBRARIES})@

    This is the command make generates and its output (the relevant part):

    @cd /home/dyeray/pfc/tracking-example/build/src && /usr/bin/cmake -E cmake_link_script CMakeFiles/tracking-example.dir/link.txt --verbose=1
    /usr/bin/c++ CMakeFiles/tracking-example.dir/main.cpp.o CMakeFiles/tracking-example.dir/MainWindow.cpp.o CMakeFiles/tracking-example.dir/glwidget.cpp.o CMakeFiles/tracking-example.dir/moc_MainWindow.cxx.o -o tracking-example -rdynamic -L/usr/lib64/lib64 -lopencv_gpu -lopencv_contrib -lopencv_legacy -lopencv_objdetect -lopencv_calib3d -lopencv_features2d -lopencv_video -lopencv_highgui -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_core -lQtCore -lQtGui -lQtOpenGL -lQtGui -lQtCore -lQtOpenGL -Wl,-rpath,/usr/lib64/lib64
    /usr/bin/ld: CMakeFiles/tracking-example.dir/glwidget.cpp.o: undefined reference to symbol 'glMatrixMode'
    /usr/bin/ld: note: 'glMatrixMode' is defined in DSO /lib64/libGL.so.1 so try adding it to the linker command line
    /lib64/libGL.so.1: could not read symbols: Invalid operation
    collect2: error: ld returned 1 exit status@

    As you see, linking to qtopengl is not enough to detect the opengl functions like glMatrixMode. If I add to target_link_libraries GL GLU then the output is:

    @/usr/bin/c++ CMakeFiles/tracking-example.dir/main.cpp.o CMakeFiles/tracking-example.dir/MainWindow.cpp.o CMakeFiles/tracking-example.dir/glwidget.cpp.o CMakeFiles/tracking-example.dir/moc_MainWindow.cxx.o -o tracking-example -rdynamic -L/usr/lib64/lib64 -lopencv_gpu -lopencv_contrib -lopencv_legacy -lopencv_objdetect -lopencv_calib3d -lopencv_features2d -lopencv_video -lopencv_highgui -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_core -lQtCore -lQtGui -lQtOpenGL -lQtGui -lQtCore -lGL -lGLU -lQtOpenGL -lGL -lGLU -Wl,-rpath,/usr/lib64/lib64
    CMakeFiles/tracking-example.dir/main.cpp.o: In function GLWidget::~GLWidget()': main.cpp:(.text._ZN8GLWidgetD2Ev[_ZN8GLWidgetD5Ev]+0x13): undefined reference to vtable for GLWidget'
    main.cpp:(.text._ZN8GLWidgetD2Ev[_ZN8GLWidgetD5Ev]+0x1f): undefined reference to vtable for GLWidget' CMakeFiles/tracking-example.dir/glwidget.cpp.o: In function GLWidget::GLWidget(QWidget*)':
    glwidget.cpp:(.text+0x45): undefined reference to vtable for GLWidget' glwidget.cpp:(.text+0x51): undefined reference to vtable for GLWidget'
    collect2: error: ld returned 1 exit status@

    I don't know if GL GLU makes the error earlier (if it hides qtopengl to the linker) or if I hace to link to this and this is other error more forward in the linking.

    UPDATE: Problem solved. I got the solution here: http://www.qtforum.org/article/38200/opengl-with-cmake.html

    1 Reply Last reply
    0

    1/1

    6 Jul 2012, 21:50

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved