Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

CLion + Qt + OpenGL



  • Good afternoon,
    I have been recently coding a project including OpenGl which compiles very well on Qt Creator.

    I have been coding on CLion all the way though and been messing up a lot trying to configure my CMakeLists. The problem seems to occur on linking the OpenGL libraries from Qt to the executable.

    cmake_minimum_required(VERSION 3.15)
    project(Toupies_DL)
    
    ADD_DEFINITIONS(-std=c++14 )
    
    set(CMAKE_CXX_STANDARD 14)
    
    
    find_package(Qt5 COMPONENTS OpenGL Widgets Core Gui Multimedia REQUIRED)
    
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_AUTOUIC ON)
    set(CMAKE_AUTORCC ON)
    
    set(QT_USE_QTOPENGL TRUE)
    
    add_definitions(${QT_DEFINITIONS})
    
    INCLUDE_DIRECTORIES(${QT_QTOPENGL_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR} )
    
    
    [...]
    
    
    add_executable(ex5
            ${QtFILES}
            ex_05/Qt_GL/main_qt_gl.cc)
    
    qt5_use_modules(ex5 Widgets OpenGL)
    target_link_libraries(ex5 ${QT_LIBRARIES} ${OPENGL_LIBRARIES})
    
    target_link_libraries(ex5 Qt5::Widgets Qt5::Core Qt5::OpenGL Qt5::Gui Qt5::Multimedia)
    

    The project builds correctly but when linking, it returns this error message :

    CMakeFiles\ex5.dir/objects.a(glwidget.cc.obj): In function `ZN8GLWidget8resizeGLEii':
    C:/Users/lgtle/Desktop/C++/programmes/projet/Toupies-DL/Toupies-DL/ex_05/Qt_GL/glwidget.cc:20: undefined reference to `_imp__glViewport@16'
    CMakeFiles\ex5.dir/objects.a(glwidget.cc.obj): In function `ZN8GLWidget7paintGLEv':
    C:/Users/lgtle/Desktop/C++/programmes/projet/Toupies-DL/Toupies-DL/ex_05/Qt_GL/glwidget.cc:39: undefined reference to `_imp__glClear@4'
    CMakeFiles\ex5.dir/objects.a(vue_opengl.cc.obj): In function `ZN9VueOpenGL4initEv':
    C:/Users/lgtle/Desktop/C++/programmes/projet/Toupies-DL/Toupies-DL/ex_05/Qt_GL/vue_opengl.cc:83: undefined reference to `_imp__glEnable@4'
    C:/Users/lgtle/Desktop/C++/programmes/projet/Toupies-DL/Toupies-DL/ex_05/Qt_GL/vue_opengl.cc:84: undefined reference to `_imp__glEnable@4'
    CMakeFiles\ex5.dir/objects.a(vue_opengl.cc.obj): In function `ZN9VueOpenGL11dessineCubeERK10QMatrix4x4':
    C:/Users/lgtle/Desktop/C++/programmes/projet/Toupies-DL/Toupies-DL/ex_05/Qt_GL/vue_opengl.cc:125: undefined reference to `_imp__glBegin@4'
    C:/Users/lgtle/Desktop/C++/programmes/projet/Toupies-DL/Toupies-DL/ex_05/Qt_GL/vue_opengl.cc:168: undefined reference to `_imp__glEnd@0'
    collect2.exe: error: ld returned 1 exit status
    
    

    It looks like Clion doesn't find the function of QtOpengl.
    Thank you in advance for your help!


  • Qt Champions 2019

    This has nothing to do with CLion - you use OPENGL_LIBRARIES but do not search for OpenGL in the first place.



  • Thanks a lot for the answer!
    I still don't see what to change though. Does it have anything to do with the CMakeLists?


  • Qt Champions 2019

    @Christian-Ehrlicher said in CLion + Qt + OpenGL:

    OPENGL_LIBRARIES

    Where do you think is this variable gets defined? You have to search for OpenGL first with FIND_PACKAGE(OpenGL)



  • Thanks a million! It is my first try with Qt, and now I see how dumb was my question, sorry for that.
    Now it works better but it says "undefined reference to `qt_static_plugin_QWindowsIntegrationPlugin()'". I will keep digging. Thanks again !


  • Qt Champions 2019

    Are you using a static Qt?



  • @Christian-Ehrlicher No, but I am working on windows, and therefore had to copy all dll's I needed in the cmake-build-debug to make it work. maybe have I forgotten one


  • Qt Champions 2019

    @LgtLeb said in CLion + Qt + OpenGL:

    and therefore had to copy all dll's I needed

    If your setup is correct you don't have to copy any dlls anywhere.


Log in to reply