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.
  • 8 Offline
    8 Offline
    8Observer8
    wrote on 5 Sept 2022, 09:58 last edited by 8Observer8 9 May 2022, 09:59
    #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 5 Sept 2022, 11:35
    0
    • 8 8Observer8
      5 Sept 2022, 09:58

      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 5 Sept 2022, 11:35 last edited by fxr65 9 May 2022, 11:36
      #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
      • 8 Offline
        8 Offline
        8Observer8
        wrote on 5 Sept 2022, 11:54 last edited by 8Observer8 9 May 2022, 11:55
        #24

        @fxr65 said in Qt6 OpenGL Static Release. Error: qopenglpaintengine.cpp:-1: error: undefined reference to `__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 5 Sept 2022, 12:27
        0
        • 8 8Observer8
          5 Sept 2022, 11:54

          @fxr65 said in Qt6 OpenGL Static Release. Error: qopenglpaintengine.cpp:-1: error: undefined reference to `__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 5 Sept 2022, 12:27 last edited by fxr65 9 May 2022, 12:28
          #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

          8 1 Reply Last reply 5 Sept 2022, 17:53
          1
          • F fxr65
            5 Sept 2022, 12:27

            @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

            8 Offline
            8 Offline
            8Observer8
            wrote on 5 Sept 2022, 17:53 last edited by
            #26

            @fxr65 said in Qt6 OpenGL Static Release. Error: qopenglpaintengine.cpp:-1: error: undefined reference to `__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 6 Sept 2022, 06:28 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();
              }
              
              8 1 Reply Last reply 6 Sept 2022, 08:28
              0
              • F fxr65
                6 Sept 2022, 06:28

                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();
                }
                
                8 Offline
                8 Offline
                8Observer8
                wrote on 6 Sept 2022, 08:28 last edited by 8Observer8 9 Jun 2022, 08:29
                #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 7 Sept 2022, 05:59
                0
                • 8 8Observer8
                  6 Sept 2022, 08: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 Offline
                  F Offline
                  fxr65
                  wrote on 7 Sept 2022, 05:59 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
                  • 8 8Observer8
                    6 Sept 2022, 08: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

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on 7 Sept 2022, 08:48 last edited by JonB 9 Jul 2022, 08:49
                    #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
                    • 8 Offline
                      8 Offline
                      8Observer8
                      wrote on 7 Sept 2022, 09:19 last edited by
                      #31

                      Okay, later maybe I will try to build latest Qt with the same configuration options as for Qt 6.2.0. But that might happen in a few months or next year because building with dynamic dlls is now preferred for me because it doesn't violate the LGPL license the way it makes building Qt static. Perhaps I will do it for the experiment, but I will not use a static assembly, so as not to violate the LGPL license.

                      JonBJ 1 Reply Last reply 7 Sept 2022, 09:21
                      0
                      • 8 8Observer8
                        7 Sept 2022, 09:19

                        Okay, later maybe I will try to build latest Qt with the same configuration options as for Qt 6.2.0. But that might happen in a few months or next year because building with dynamic dlls is now preferred for me because it doesn't violate the LGPL license the way it makes building Qt static. Perhaps I will do it for the experiment, but I will not use a static assembly, so as not to violate the LGPL license.

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on 7 Sept 2022, 09:21 last edited by
                        #32

                        @8Observer8
                        Then why can't you just give up on static now and go with the dynamic which you say already works and doesn't have all this heartache...? Anyway, up to you.

                        8 1 Reply Last reply 7 Sept 2022, 09:27
                        0
                        • JonBJ JonB
                          7 Sept 2022, 09:21

                          @8Observer8
                          Then why can't you just give up on static now and go with the dynamic which you say already works and doesn't have all this heartache...? Anyway, up to you.

                          8 Offline
                          8 Offline
                          8Observer8
                          wrote on 7 Sept 2022, 09:27 last edited by 8Observer8 9 Jul 2022, 09:39
                          #33

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

                          Then why can't you just give up on static now and go with the dynamic which you say already works and doesn't have all this heartache...?

                          I already did it. I just leave here the links to the installed Qt 6.2.0 and the static build for it:

                          • Qt6.2.0_MinGW_8.1.0_64bit.zip (942 MB)
                          • Qt6.2.0_Static.zip (194)

                          But be aware that using static Qt violates the LGPL license. You can use static Qt under the GPL license, but you must disclose the source code for your product, or for a commercial Qt license.

                          1 Reply Last reply
                          0
                          • P Offline
                            P Offline
                            PythonDuncan
                            wrote on 29 Sept 2023, 15:17 last edited by
                            #34

                            I also had this issue today, I followed https://medium.com/swlh/setting-opengl-for-windows-d0b45062caf to install opengl/glew/freeglut and added win32: LIBS += -lfreeglut -lglew32 -lopengl32 in the .pro file. Now everything is working.
                            PS, I strongly recommend to install libs via https://www.msys2.org/. It's quite simple and convenient.

                            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