Home:ALL Converter>Linker errors when using OpenGL in Qt

Linker errors when using OpenGL in Qt

Ask Time:2013-02-04T05:04:50         Author:aPerfectMisterMan

Json Formatter

I am trying to use OpenGL with Qt. I was following this example: http://qt-project.org/doc/qt-5.0/qtgui/openglwindow.html using Qt 5 build for msvc2012. In the end I am getting the following errors:

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

I can see that it has to do with the linking of OpenGL functions but I don't have much knowledge about linking.

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

Author:aPerfectMisterMan,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/14677304/linker-errors-when-using-opengl-in-qt
datenwolf :

You must add opengl32.lib to the list of linked libraries. Adding the OpenGL module in the QtCreator .pro file should do the trick\n\nQT += opengl\n",
2013-02-03T22:32:42
user362638 :

Have you added the OpenGL module in your pro file like this:\n\nQT += opengl\n",
2013-02-03T22:22:23
zh_ :

If you use Qt 5, then add next lib in you project file (*.pro)\n\nLIBS += -LD:\\Qt\\5.5\\mingw492_32\\lib\\libQt5OpenGL.a -lopengl32\n\n\nD:\\Qt\\5.5\\mingw492_32\\lib\\libQt5OpenGL.a is path.",
2016-03-31T11:59:33
yy