Linker errors when using OpenGL in Qt

I am trying to use OpenGL with Qt. I followed this example: http://qt-project.org/doc/qt-5.0/qtgui/openglwindow.html using the Qt 5 build for msvc2012. As a result, I get the following errors:

  • error LNK2019: unresolved external symbol _imp_glClear @ 4 referencing function public: virtual void __thiscall OpenGLWindow :: render (void) "(? render @OpenGLWindow @@ UAEXXZ) D: \ Documents \ Code \ Qt Projects \ qttest2 \ qttest2 \ openglwindow .obj qttest2
  • error LNK2001: unresolved external symbol _imp_glClear @ 4 D: \ Documents \ Code \ Qt Projects \ qttest2 \ qttest2 \ trianglewindow.obj qttest2
  • error LNK2019: unresolved external symbol _imp_glDrawArrays @ 12 specified in function "public: virtual void __thiscall TriangleWindow :: render (void)" (? render @TriangleWindow @@ UAEXXZ) D: \ Documents \ Code \ Qt Projects \ qttest2 \ qttest2 \ trianglewindow.obj qttest2
  • error LNK2019: unresolved external symbol _imp_glViewport @ 16 specified in function "public: virtual void" __thiscall TriangleWindow :: render (void) "(? render @TriangleWindow @@ UAEXXZ) D: \ Documents \ Code \ Qt Projects \ qttest2 \ qttest2 \ trianglewindow.obj qttest2
  • error LNK1120: 3 unresolved external D: \ Documents \ Code \ Qt Projects \ qttest2 \ Win32 \ Debug \ qttest2.exe qttest2

I can see it has to do with OpenGL function binding, but I have little knowledge of binding.

I get errors even if I copy the source code from the OpenGLWindow example.

+3


source to share


4 answers


You have to add opengl32.lib

linked libraries to the list. Adding an OpenGL module to the QtCreator.pro file should do the trick



QT += opengl

      

+3


source


Have you added the OpenGL module to your pro file like this:



QT += opengl

      

+2


source


If you are using Qt 5 add the following lib to your project file (* .pro)

LIBS += -LD:\Qt\5.5\mingw492_32\lib\libQt5OpenGL.a -lopengl32

      

D:\Qt\5.5\mingw492_32\lib\libQt5OpenGL.a

- way.

+1


source


In a linux environment, installing the [mesa] library may solve the problem. [lib32-mesa, open source implementation of OpenGL]

[pacman -S mesa ]       *Arch Linux 
[apt-get install mesa]  *ubuntu/Mint/Raspbian 

      

0


source







All Articles