Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. Qt6 OpenGL Static Release. Error: qopenglpaintengine.cpp:-1: error: undefined reference to `__imp_glMatrixMode'

Qt6 OpenGL Static Release. Error: qopenglpaintengine.cpp:-1: error: undefined reference to `__imp_glMatrixMode'

Scheduled Pinned Locked Moved Unsolved Qt 6
34 Posts 6 Posters 5.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.
  • Christian EhrlicherC Offline
    Christian EhrlicherC Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on last edited by
    #11

    Ok - please take a look at this answer: https://stackoverflow.com/questions/9336263/glfw-undefined-references

    Looks like MinGW split up the libs different to MSVC.

    Also you can try to move -lopengl32 after all the other libs (for testing purposes directly on the command line)

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    1 Reply Last reply
    0
    • 8Observer88 Offline
      8Observer88 Offline
      8Observer8
      wrote on last edited by 8Observer8
      #12

      I tried to delete this line win32: LIBS += -lopengl32:

      QT       += core gui openglwidgets
      
      INCLUDEPATH += "C:\Program Files\FMOD SoundSystem\FMOD Studio API Windows\api\core\inc"
      LIBS += "C:\Program Files\FMOD SoundSystem\FMOD Studio API Windows\api\core\lib\x64\fmod.dll"
      
      INCLUDEPATH += "E:\Libs\box2d-2.4.1-mingw-64-bit\include"
      LIBS += -L"E:\Libs\box2d-2.4.1-mingw-64-bit\lib"
      LIBS += -lbox2d
      
      greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
      
      CONFIG += c++11
      
      # You can make your code fail to compile if it uses deprecated APIs.
      # In order to do so, uncomment the following line.
      #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
      
      SOURCES += \
          ColliderEdge.cpp \
          DebugDrawer.cpp \
          VertexBuffers.cpp \
          main.cpp \
          Widget.cpp
      
      HEADERS += \
          ColliderEdge.h \
          DebugDrawer.h \
          VertexBuffers.h \
          Widget.h
      
      # Default rules for deployment.
      qnx: target.path = /tmp/$${TARGET}/bin
      else: unix:!android: target.path = /opt/$${TARGET}/bin
      !isEmpty(target.path): INSTALLS += target
      
      RESOURCES += \
          Levels.qrc \
          Shaders.qrc \
          Sounds.qrc \
          Sprites.qrc
      

      I tried to place it at the end:

      QT       += core gui openglwidgets
      
      INCLUDEPATH += "C:\Program Files\FMOD SoundSystem\FMOD Studio API Windows\api\core\inc"
      LIBS += "C:\Program Files\FMOD SoundSystem\FMOD Studio API Windows\api\core\lib\x64\fmod.dll"
      
      INCLUDEPATH += "E:\Libs\box2d-2.4.1-mingw-64-bit\include"
      LIBS += -L"E:\Libs\box2d-2.4.1-mingw-64-bit\lib"
      LIBS += -lbox2d
      
      win32: LIBS += -lopengl32
      
      greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
      
      CONFIG += c++11
      
      # You can make your code fail to compile if it uses deprecated APIs.
      # In order to do so, uncomment the following line.
      #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
      
      SOURCES += \
          ColliderEdge.cpp \
          DebugDrawer.cpp \
          VertexBuffers.cpp \
          main.cpp \
          Widget.cpp
      
      HEADERS += \
          ColliderEdge.h \
          DebugDrawer.h \
          VertexBuffers.h \
          Widget.h
      
      # Default rules for deployment.
      qnx: target.path = /tmp/$${TARGET}/bin
      else: unix:!android: target.path = /opt/$${TARGET}/bin
      !isEmpty(target.path): INSTALLS += target
      
      RESOURCES += \
          Levels.qrc \
          Shaders.qrc \
          Sounds.qrc \
          Sprites.qrc
      

      I tried to place it at the beginning:

      QT       += core gui openglwidgets
      
      win32: LIBS += -lopengl32
      
      INCLUDEPATH += "C:\Program Files\FMOD SoundSystem\FMOD Studio API Windows\api\core\inc"
      LIBS += "C:\Program Files\FMOD SoundSystem\FMOD Studio API Windows\api\core\lib\x64\fmod.dll"
      
      INCLUDEPATH += "E:\Libs\box2d-2.4.1-mingw-64-bit\include"
      LIBS += -L"E:\Libs\box2d-2.4.1-mingw-64-bit\lib"
      LIBS += -lbox2d
      
      greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
      
      CONFIG += c++11
      
      # You can make your code fail to compile if it uses deprecated APIs.
      # In order to do so, uncomment the following line.
      #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
      
      SOURCES += \
          ColliderEdge.cpp \
          DebugDrawer.cpp \
          VertexBuffers.cpp \
          main.cpp \
          Widget.cpp
      
      HEADERS += \
          ColliderEdge.h \
          DebugDrawer.h \
          VertexBuffers.h \
          Widget.h
      
      # Default rules for deployment.
      qnx: target.path = /tmp/$${TARGET}/bin
      else: unix:!android: target.path = /opt/$${TARGET}/bin
      !isEmpty(target.path): INSTALLS += target
      
      RESOURCES += \
          Levels.qrc \
          Shaders.qrc \
          Sounds.qrc \
          Sprites.qrc
      

      But the result is the same. It compiles without errors for dynamic version of Qt (both for Debug and Release) and it does not work for static release only.

      Christian EhrlicherC 1 Reply Last reply
      0
      • 8Observer88 8Observer8

        I tried to delete this line win32: LIBS += -lopengl32:

        QT       += core gui openglwidgets
        
        INCLUDEPATH += "C:\Program Files\FMOD SoundSystem\FMOD Studio API Windows\api\core\inc"
        LIBS += "C:\Program Files\FMOD SoundSystem\FMOD Studio API Windows\api\core\lib\x64\fmod.dll"
        
        INCLUDEPATH += "E:\Libs\box2d-2.4.1-mingw-64-bit\include"
        LIBS += -L"E:\Libs\box2d-2.4.1-mingw-64-bit\lib"
        LIBS += -lbox2d
        
        greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
        
        CONFIG += c++11
        
        # You can make your code fail to compile if it uses deprecated APIs.
        # In order to do so, uncomment the following line.
        #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
        
        SOURCES += \
            ColliderEdge.cpp \
            DebugDrawer.cpp \
            VertexBuffers.cpp \
            main.cpp \
            Widget.cpp
        
        HEADERS += \
            ColliderEdge.h \
            DebugDrawer.h \
            VertexBuffers.h \
            Widget.h
        
        # Default rules for deployment.
        qnx: target.path = /tmp/$${TARGET}/bin
        else: unix:!android: target.path = /opt/$${TARGET}/bin
        !isEmpty(target.path): INSTALLS += target
        
        RESOURCES += \
            Levels.qrc \
            Shaders.qrc \
            Sounds.qrc \
            Sprites.qrc
        

        I tried to place it at the end:

        QT       += core gui openglwidgets
        
        INCLUDEPATH += "C:\Program Files\FMOD SoundSystem\FMOD Studio API Windows\api\core\inc"
        LIBS += "C:\Program Files\FMOD SoundSystem\FMOD Studio API Windows\api\core\lib\x64\fmod.dll"
        
        INCLUDEPATH += "E:\Libs\box2d-2.4.1-mingw-64-bit\include"
        LIBS += -L"E:\Libs\box2d-2.4.1-mingw-64-bit\lib"
        LIBS += -lbox2d
        
        win32: LIBS += -lopengl32
        
        greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
        
        CONFIG += c++11
        
        # You can make your code fail to compile if it uses deprecated APIs.
        # In order to do so, uncomment the following line.
        #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
        
        SOURCES += \
            ColliderEdge.cpp \
            DebugDrawer.cpp \
            VertexBuffers.cpp \
            main.cpp \
            Widget.cpp
        
        HEADERS += \
            ColliderEdge.h \
            DebugDrawer.h \
            VertexBuffers.h \
            Widget.h
        
        # Default rules for deployment.
        qnx: target.path = /tmp/$${TARGET}/bin
        else: unix:!android: target.path = /opt/$${TARGET}/bin
        !isEmpty(target.path): INSTALLS += target
        
        RESOURCES += \
            Levels.qrc \
            Shaders.qrc \
            Sounds.qrc \
            Sprites.qrc
        

        I tried to place it at the beginning:

        QT       += core gui openglwidgets
        
        win32: LIBS += -lopengl32
        
        INCLUDEPATH += "C:\Program Files\FMOD SoundSystem\FMOD Studio API Windows\api\core\inc"
        LIBS += "C:\Program Files\FMOD SoundSystem\FMOD Studio API Windows\api\core\lib\x64\fmod.dll"
        
        INCLUDEPATH += "E:\Libs\box2d-2.4.1-mingw-64-bit\include"
        LIBS += -L"E:\Libs\box2d-2.4.1-mingw-64-bit\lib"
        LIBS += -lbox2d
        
        greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
        
        CONFIG += c++11
        
        # You can make your code fail to compile if it uses deprecated APIs.
        # In order to do so, uncomment the following line.
        #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
        
        SOURCES += \
            ColliderEdge.cpp \
            DebugDrawer.cpp \
            VertexBuffers.cpp \
            main.cpp \
            Widget.cpp
        
        HEADERS += \
            ColliderEdge.h \
            DebugDrawer.h \
            VertexBuffers.h \
            Widget.h
        
        # Default rules for deployment.
        qnx: target.path = /tmp/$${TARGET}/bin
        else: unix:!android: target.path = /opt/$${TARGET}/bin
        !isEmpty(target.path): INSTALLS += target
        
        RESOURCES += \
            Levels.qrc \
            Shaders.qrc \
            Sounds.qrc \
            Sprites.qrc
        

        But the result is the same. It compiles without errors for dynamic version of Qt (both for Debug and Release) and it does not work for static release only.

        Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #13

        @8Observer8 said in Qt6 OpenGL Static Release. Error: qopenglpaintengine.cpp:-1: error: undefined reference to `__imp_glMatrixMode':

        I tried to delete this line win32: LIBS += -lopengl32:

        Why? Did you read my post, the so post and what I suggested?

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        8Observer88 1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          @8Observer8 said in Qt6 OpenGL Static Release. Error: qopenglpaintengine.cpp:-1: error: undefined reference to `__imp_glMatrixMode':

          I tried to delete this line win32: LIBS += -lopengl32:

          Why? Did you read my post, the so post and what I suggested?

          8Observer88 Offline
          8Observer88 Offline
          8Observer8
          wrote on last edited by
          #14

          @Christian-Ehrlicher said in Qt6 OpenGL Static Release. Error: qopenglpaintengine.cpp:-1: error: undefined reference to `__imp_glMatrixMode':

          Why? Did you read my post, the so post and what I suggested?

          I tried removing this line as an experiment to see if there would be more errors, but the number of errors remained the same. This is some kind of mystic. It's as if the linker is ignoring -lopengl32

          1 Reply Last reply
          0
          • 8Observer88 8Observer8

            Maybe should I include -opengl (or something like this) to config command before the static build?

            configure -prefix "C:\Qt6.2.0_Static" -static -static-runtime -release -opensource -confirm-license -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -opengl desktop -sql-odbc -sql-sqlite -nomake tools -nomake examples -nomake tests -skip qttools -skip qtquick3d -skip qt5compat -skip qtquicktimeline -skip qtwebengine -skip qtactiveqt -skip qtcharts -skip qtconnectivity -skip qtdatavis3d -skip qtimageformats -skip qtlottie -skip qtnetworkauth -skip qtremoteobjects -skip qtvirtualkeyboard -skip qtserialbus -skip qtserialport -skip qtwebchannel -skip qtwebview -skip qtwayland -skip qtscxml -skip qtmqtt -skip qtopcua -skip qtsvg -skip qtdoc -skip qttranslations

            8Observer88 Offline
            8Observer88 Offline
            8Observer8
            wrote on last edited by 8Observer8
            #15

            @8Observer8 said in Qt6 OpenGL Static Release. Error: qopenglpaintengine.cpp:-1: error: undefined reference to `__imp_glMatrixMode':

            Maybe should I include -opengl (or something like this) to config command before the static build?

            configure -prefix "C:\Qt6.2.0_Static" -static -static-runtime -release -opensource -confirm-license -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -opengl desktop -sql-odbc -sql-sqlite -nomake tools -nomake examples -nomake tests -skip qttools -skip qtquick3d -skip qt5compat -skip qtquicktimeline -skip qtwebengine -skip qtactiveqt -skip qtcharts -skip qtconnectivity -skip qtdatavis3d -skip qtimageformats -skip qtlottie -skip qtnetworkauth -skip qtremoteobjects -skip qtvirtualkeyboard -skip qtserialbus -skip qtserialport -skip qtwebchannel -skip qtwebview -skip qtwayland -skip qtscxml -skip qtmqtt -skip qtopcua -skip qtsvg -skip qtdoc -skip qttranslations

            Here is -opengl

            1 Reply Last reply
            0
            • 8Observer88 Offline
              8Observer88 Offline
              8Observer8
              wrote on last edited by 8Observer8
              #16

              @Christian-Ehrlicher said in Qt6 OpenGL Static Release. Error: qopenglpaintengine.cpp:-1: error: undefined reference to `__imp_glMatrixMode':

              Why? Did you read my post, the so post and what I suggested?

              Yes, I did. For example, I tried this: In the linker, at Windows, MinGW: -lglew32 -lglfw3 -lopengl32 -lglu32 -lgdi32 But I do not use GLFW and GLEW. I tried these keys: lglu32 -lgdi32. I made a simple example in OpenGL. It compiles without errors for dynamic version of Qt 6.2.0 (both: for Debug and for Release builds) but it does not compile for static release only. Errors:

              qopenglpaintengine.cpp:-1: error: undefined reference to `__imp_glMatrixMode'
              qopenglpaintengine.cpp:-1: error: undefined reference to `__imp_glLoadIdentity'
              qopenglpaintengine.cpp:-1: error: undefined reference to `__imp_glOrtho'
              qopenglpaintengine.cpp:-1: error: undefined reference to `__imp_glLoadMatrixf'
              

              pro

              QT       += core gui openglwidgets
              win32: LIBS += -lopengl32 -lglu32 -lgdi32
              

              main.cpp

              
              #include <QtWidgets/QApplication>
              #include <QtOpenGLWidgets/QOpenGLWidget>
              #include <QtGui/QOpenGLFunctions>
              
              class Widget : public QOpenGLWidget, QOpenGLFunctions
              {
              private:
                  void initializeGL() override
                  {
                      initializeOpenGLFunctions();
                      glClearColor(0.3f, 0.3f, 0.3f, 1.f);
                  }
              
                  void paintGL() override
                  {
                      glClear(GL_COLOR_BUFFER_BIT);
                  }
              };
              
              int main(int argc, char *argv[])
              {
                  QApplication a(argc, argv);
                  Widget w;
                  w.show();
                  return a.exec();
              }
              
              1 Reply Last reply
              0
              • 8Observer88 Offline
                8Observer88 Offline
                8Observer8
                wrote on last edited by 8Observer8
                #17

                What else should I try?

                1 Reply Last reply
                0
                • 8Observer88 Offline
                  8Observer88 Offline
                  8Observer8
                  wrote on last edited by 8Observer8
                  #18

                  I tried putting -lopengl32 at the end of the line: win32: LIBS += -lglu32 -lgdi32 -lopengl32

                  But:

                  a640349d-cf98-4f39-af5b-cff441c62b82-image.png

                  1 Reply Last reply
                  0
                  • 8Observer88 Offline
                    8Observer88 Offline
                    8Observer8
                    wrote on last edited by 8Observer8
                    #19

                    I tried to create a question on StackOverflow: Failed to build OpenGL project with static Qt 6.2.0 but my question was closed as duplicate:

                    This question already has answers here:
                    What is an undefined reference/unresolved external symbol error and how do I fix it? (38 answers)

                    If anyone encounters this problem and solves it, then please write here how you solved this problem. I did everything I could.

                    1 Reply Last reply
                    0
                    • F Offline
                      F Offline
                      fxr65
                      wrote on last edited by fxr65
                      #20

                      Probably you have to add the path to the libraries like this (in case the libs are in your project working dir):
                      LIBS += -L$$PWD -l<blah>
                      At least this helped me, as I had to add a lib to my project.

                      1 Reply Last reply
                      0
                      • 8Observer88 Offline
                        8Observer88 Offline
                        8Observer8
                        wrote on last edited by 8Observer8
                        #21

                        @fxr65 I think -lopengl32 references to "opengl32.dll". I tried to copy "opengl32.dll" from "C:\Windows\System32" to my working directory:

                        3cfe0235-491d-43ed-821a-59e58ab64178-image.png

                        I added -L$$PWD to pro file:

                        QT += core gui openglwidgets
                        
                        win32: LIBS += -L$$PWD -lopengl32
                        
                        CONFIG += c++11
                        
                        SOURCES += \
                            main.cpp
                        

                        But I see the same errors:

                        153ba0e9-eb67-49ad-9343-bbc624aaa645-image.png

                        1 Reply Last reply
                        0
                        • 8Observer88 Offline
                          8Observer88 Offline
                          8Observer8
                          wrote on last edited by 8Observer8
                          #22

                          I have Windows 10 64 bit and Qt 6.2.0 MingGW 64 bit. I think in this case I should copy "opengl32.dll" from the "C:\Windows\SysWOW64" folder to my project directory. I tried it but I have the same errors as above.

                          F 1 Reply Last reply
                          0
                          • 8Observer88 8Observer8

                            I have Windows 10 64 bit and Qt 6.2.0 MingGW 64 bit. I think in this case I should copy "opengl32.dll" from the "C:\Windows\SysWOW64" folder to my project directory. I tried it but I have the same errors as above.

                            F Offline
                            F Offline
                            fxr65
                            wrote on last edited by fxr65
                            #23

                            @8Observer8 I think you should get opengl32.lib for linker instead of dll. The dll for runtime depends on your app. In case your app is 32bit the dll is in syswow64 and for a 64bit app the dll is in system32. But you do not have to copy the dlls, as all system folders are in path.

                            1 Reply Last reply
                            0
                            • 8Observer88 Offline
                              8Observer88 Offline
                              8Observer8
                              wrote on last edited by 8Observer8
                              #24

                              @fxr65 said in Qt6 OpenGL Static Release. Error: qopenglpaintengine.cpp:-1: error: undefined reference to &#x60;__imp_glMatrixMode':

                              I think you should get opengl32.lib for linker instead of dll.

                              In my case it must be "libopengl.a" because I use MinGW instead of MSVC. But where to find "libopengl.a"? Why does my example work for dynamic Qt and it does not work for static Qt?

                              F 1 Reply Last reply
                              0
                              • 8Observer88 8Observer8

                                @fxr65 said in Qt6 OpenGL Static Release. Error: qopenglpaintengine.cpp:-1: error: undefined reference to &#x60;__imp_glMatrixMode':

                                I think you should get opengl32.lib for linker instead of dll.

                                In my case it must be "libopengl.a" because I use MinGW instead of MSVC. But where to find "libopengl.a"? Why does my example work for dynamic Qt and it does not work for static Qt?

                                F Offline
                                F Offline
                                fxr65
                                wrote on last edited by fxr65
                                #25

                                @8Observer8 I use also mingw for compilation on a W10. Last week I also struggled to get a library recognized by the linker. After setting L and l it worked. libopengl.a is on linux systems, but as you are on W10 you need opengl32.lib. You can find the lib inside the windows sdk.
                                See https://stackoverflow.com/questions/22231740/opengl32-lib-not-linking-properly

                                8Observer88 1 Reply Last reply
                                1
                                • F fxr65

                                  @8Observer8 I use also mingw for compilation on a W10. Last week I also struggled to get a library recognized by the linker. After setting L and l it worked. libopengl.a is on linux systems, but as you are on W10 you need opengl32.lib. You can find the lib inside the windows sdk.
                                  See https://stackoverflow.com/questions/22231740/opengl32-lib-not-linking-properly

                                  8Observer88 Offline
                                  8Observer88 Offline
                                  8Observer8
                                  wrote on last edited by
                                  #26

                                  @fxr65 said in Qt6 OpenGL Static Release. Error: qopenglpaintengine.cpp:-1: error: undefined reference to &#x60;__imp_glMatrixMode':

                                  libopengl.a is on linux systems, but as you are on W10 you need opengl32.lib

                                  I thought that MinGW uses the .a extension only. It compiles all libraries to '.a'. I tried to find libopengl32.a here C:\Qt6\6.2.0\mingw81_64\lib but I didn't find it.

                                  @fxr65 I found OpenGL32.lib in this folder: C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\um\x64:
                                  8a5f3232-529c-4630-9dac-b18f6d988a3b-image.png

                                  I copied it to my project directory:

                                  b6fbd5f7-32d5-446b-a7ea-ba33f574ef62-image.png

                                  But it doesn't work:

                                  f42deef1-4576-454d-bb66-32c1001e1f37-image.png

                                  QtStaticOpenGL.pro

                                  QT += core gui openglwidgets
                                  
                                  win32: LIBS += -L$$PWD -lopengl32
                                  
                                  CONFIG += c++11
                                  
                                  SOURCES += \
                                      main.cpp
                                  

                                  main.cpp

                                  
                                  #include <QtWidgets/QApplication>
                                  #include <QtOpenGLWidgets/QOpenGLWidget>
                                  #include <QtGui/QOpenGLFunctions>
                                  
                                  class Widget : public QOpenGLWidget, QOpenGLFunctions
                                  {
                                  private:
                                      void initializeGL() override
                                      {
                                          initializeOpenGLFunctions();
                                          glClearColor(0.3f, 0.3f, 0.3f, 1.f);
                                      }
                                  
                                      void paintGL() override
                                      {
                                          glClear(GL_COLOR_BUFFER_BIT);
                                      }
                                  };
                                  
                                  int main(int argc, char *argv[])
                                  {
                                      QApplication a(argc, argv);
                                      Widget w;
                                      w.show();
                                      return a.exec();
                                  }
                                  
                                  1 Reply Last reply
                                  0
                                  • F Offline
                                    F Offline
                                    fxr65
                                    wrote on last edited by
                                    #27

                                    On my Qt 5.12 this compiles, links and runs:
                                    opengl.pro

                                    QT += core gui widgets
                                    
                                    win32: LIBS += -L$$PWD -lopengl32
                                    
                                    CONFIG += c++11
                                    
                                    SOURCES += \
                                        main.cpp
                                    

                                    main.cpp

                                    #include <QtWidgets/QApplication.h>
                                    #include <QtWidgets/QOpenGLWidget.h>
                                    #include <QtGui/QOpenGLFunctions.h>
                                    
                                    class Widget : public QOpenGLWidget, QOpenGLFunctions
                                    {
                                    private:
                                        void initializeGL() override
                                        {
                                            initializeOpenGLFunctions();
                                            glClearColor(0.3f, 0.3f, 0.3f, 1.f);
                                        }
                                    
                                        void paintGL() override
                                        {
                                            glClear(GL_COLOR_BUFFER_BIT);
                                        }
                                    };
                                    
                                    int main(int argc, char *argv[])
                                    {
                                        QApplication a(argc, argv);
                                        Widget w;
                                        w.show();
                                        return a.exec();
                                    }
                                    

                                    Also this compiles, links and runs:
                                    opengl2.pro

                                    QT += core gui widgets
                                    
                                    win32:
                                    
                                    CONFIG += c++11
                                    
                                    SOURCES += \
                                        main.cpp \
                                        widget.cpp
                                    
                                    HEADERS += \
                                      widget.h
                                    

                                    widget.h

                                    #ifndef WIDGET_H
                                    #define WIDGET_H
                                    
                                    #include <QtWidgets/QOpenGLWidget>
                                    #include <QtGui/QOpenGLFunctions>
                                    
                                    class Widget : public QOpenGLWidget, protected QOpenGLFunctions
                                    {
                                        Q_OBJECT
                                    
                                    public:
                                        Widget(QWidget *parent = nullptr);
                                        ~Widget();
                                    
                                    private:
                                        void initializeGL() override;
                                        void paintGL() override;
                                        void resizeGL(int w, int h) override;
                                    };
                                    #endif // WIDGET_H
                                    

                                    widget.cpp

                                    #include "widget.h"
                                    
                                    Widget::Widget(QWidget *parent)
                                        : QOpenGLWidget(parent)
                                    {
                                        resize(500, 500);
                                        setWindowTitle("Qt6 C++, OpenGL ES 2.0");
                                    }
                                    
                                    Widget::~Widget()
                                    {
                                    }
                                    
                                    void Widget::initializeGL()
                                    {
                                        initializeOpenGLFunctions();
                                        glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
                                    }
                                    
                                    void Widget::paintGL()
                                    {
                                        glClear(GL_COLOR_BUFFER_BIT);
                                    }
                                    
                                    void Widget::resizeGL(int w, int h)
                                    {
                                        glViewport(0, 0, w, h);
                                    }
                                    

                                    main.cpp

                                    #include "Widget.h"
                                    
                                    #include <QtWidgets/QApplication>
                                    
                                    int main(int argc, char *argv[])
                                    {
                                        QApplication a(argc, argv);
                                        Widget w;
                                        w.show();
                                        return a.exec();
                                    }
                                    
                                    8Observer88 1 Reply Last reply
                                    0
                                    • F fxr65

                                      On my Qt 5.12 this compiles, links and runs:
                                      opengl.pro

                                      QT += core gui widgets
                                      
                                      win32: LIBS += -L$$PWD -lopengl32
                                      
                                      CONFIG += c++11
                                      
                                      SOURCES += \
                                          main.cpp
                                      

                                      main.cpp

                                      #include <QtWidgets/QApplication.h>
                                      #include <QtWidgets/QOpenGLWidget.h>
                                      #include <QtGui/QOpenGLFunctions.h>
                                      
                                      class Widget : public QOpenGLWidget, QOpenGLFunctions
                                      {
                                      private:
                                          void initializeGL() override
                                          {
                                              initializeOpenGLFunctions();
                                              glClearColor(0.3f, 0.3f, 0.3f, 1.f);
                                          }
                                      
                                          void paintGL() override
                                          {
                                              glClear(GL_COLOR_BUFFER_BIT);
                                          }
                                      };
                                      
                                      int main(int argc, char *argv[])
                                      {
                                          QApplication a(argc, argv);
                                          Widget w;
                                          w.show();
                                          return a.exec();
                                      }
                                      

                                      Also this compiles, links and runs:
                                      opengl2.pro

                                      QT += core gui widgets
                                      
                                      win32:
                                      
                                      CONFIG += c++11
                                      
                                      SOURCES += \
                                          main.cpp \
                                          widget.cpp
                                      
                                      HEADERS += \
                                        widget.h
                                      

                                      widget.h

                                      #ifndef WIDGET_H
                                      #define WIDGET_H
                                      
                                      #include <QtWidgets/QOpenGLWidget>
                                      #include <QtGui/QOpenGLFunctions>
                                      
                                      class Widget : public QOpenGLWidget, protected QOpenGLFunctions
                                      {
                                          Q_OBJECT
                                      
                                      public:
                                          Widget(QWidget *parent = nullptr);
                                          ~Widget();
                                      
                                      private:
                                          void initializeGL() override;
                                          void paintGL() override;
                                          void resizeGL(int w, int h) override;
                                      };
                                      #endif // WIDGET_H
                                      

                                      widget.cpp

                                      #include "widget.h"
                                      
                                      Widget::Widget(QWidget *parent)
                                          : QOpenGLWidget(parent)
                                      {
                                          resize(500, 500);
                                          setWindowTitle("Qt6 C++, OpenGL ES 2.0");
                                      }
                                      
                                      Widget::~Widget()
                                      {
                                      }
                                      
                                      void Widget::initializeGL()
                                      {
                                          initializeOpenGLFunctions();
                                          glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
                                      }
                                      
                                      void Widget::paintGL()
                                      {
                                          glClear(GL_COLOR_BUFFER_BIT);
                                      }
                                      
                                      void Widget::resizeGL(int w, int h)
                                      {
                                          glViewport(0, 0, w, h);
                                      }
                                      

                                      main.cpp

                                      #include "Widget.h"
                                      
                                      #include <QtWidgets/QApplication>
                                      
                                      int main(int argc, char *argv[])
                                      {
                                          QApplication a(argc, argv);
                                          Widget w;
                                          w.show();
                                          return a.exec();
                                      }
                                      
                                      8Observer88 Offline
                                      8Observer88 Offline
                                      8Observer8
                                      wrote on last edited by 8Observer8
                                      #28

                                      @fxr65 said in Qt6 OpenGL Static Release. Error: qopenglpaintengine.cpp:-1: error: undefined reference to &#x60;__imp_glMatrixMode':

                                      On my Qt 5.12 this compiles, links and runs

                                      Yes, Qt 5.15.2 Static works for me too. The problem is only with Qt 6.2.0

                                      F JonBJ 2 Replies Last reply
                                      0
                                      • 8Observer88 8Observer8

                                        @fxr65 said in Qt6 OpenGL Static Release. Error: qopenglpaintengine.cpp:-1: error: undefined reference to &#x60;__imp_glMatrixMode':

                                        On my Qt 5.12 this compiles, links and runs

                                        Yes, Qt 5.15.2 Static works for me too. The problem is only with Qt 6.2.0

                                        F Offline
                                        F Offline
                                        fxr65
                                        wrote on last edited by
                                        #29

                                        @8Observer8 It seems I can't assist further as it compiles, links and runs on my 6.3.1. The second sample opengl2 did also compile and run after adding "win32: LIBS += -L$$PWD -lopengl32".

                                        1 Reply Last reply
                                        1
                                        • 8Observer88 8Observer8

                                          @fxr65 said in Qt6 OpenGL Static Release. Error: qopenglpaintengine.cpp:-1: error: undefined reference to &#x60;__imp_glMatrixMode':

                                          On my Qt 5.12 this compiles, links and runs

                                          Yes, Qt 5.15.2 Static works for me too. The problem is only with Qt 6.2.0

                                          JonBJ Offline
                                          JonBJ Offline
                                          JonB
                                          wrote on last edited by JonB
                                          #30

                                          @8Observer8
                                          Since @fxr65 says it all works under 6.3.1 the first thing would be for you check whether that does work for you too. That should clarify whether it is a Qt issue or an individual build issue.

                                          1 Reply Last reply
                                          1

                                          • Login

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