Qt 5.5 with qmake: Linker cannot resolve OpenGL function calls

When using Qt 5.5 qmake and MSVC 13 to compile a basic, templated Qt application with some fundamental OpenGL function calls, I get the following linker errors:

glwidget.obj:-1: error: LNK2019: unresolved external symbol __imp__glClear@4 referenced in function "public: virtual void __thiscall GLWidget::initializeGL(void)" ( ?initializeGL@GLWidget @@UAEXXZ) glwidget.obj:-1: error: LNK2019: unresolved external symbol __imp__glClearColor@16 referenced in function "public: virtual void __thiscall GLWidget::initializeGL(void)" ( ?initializeGL@GLWidget @@UAEXXZ) debug\OpenGLApp.exe:-1: error: LNK1120: 2 unresolved externals 

I have:

  • Specified QT + = opengl
  • Explicitly specified CONFIG + = windows (apparently + = console disables gui functions)

.pro file:

 QT += core gui opengl widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets opengl TARGET = OpenGLApp TEMPLATE = app CONFIG += windows SOURCES += main.cpp\ mainwindow.cpp \ glwidget.cpp HEADERS += mainwindow.h \ glwidget.h 

glwidget.cpp file:

 #include "glwidget.h" GLWidget::GLWidget(QWidget *parent) : QOpenGLWidget(parent) { } void GLWidget::initializeGL() { glClearColor(0.0f, 0.0f, 1.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); } 

Glwidget.h file:

 #include <QOpenGLWidget> #include <QOpenGLFunctions> class GLWidget : public QOpenGLWidget { Q_OBJECT public: GLWidget(QWidget *); void initializeGL(); void resizeGL(); void PaintGL(); }; 

In another almost identical test program, I had the same problem as the linker could not resolve OpenGL function calls. Instead of using CMake, in particular with the following line "find_package (OpenGL REQUIRED)" and adding "$ OPENGL_LIBRARIES" to "target_link_libraries", I was able to solve the problem:

 #Qt5 find_package(Qt5Core REQUIRED) find_package(Qt5Widgets REQUIRED) find_package(Qt5Gui REQUIRED) find_package(Qt5OpenGL REQUIRED) #OpenGL find_package(OpenGL REQUIRED) target_link_libraries(${PROJECT_NAME} Qt5::Widgets Qt5::Gui Qt5::Core Qt5::OpenGL ${OPENGL_LIBRARIES}) 

Therefore, I suspect that qmake cannot find the OpenGL libraries, although I am not sure how to check and what could be the reason for this, and therefore it would be useful if someone could tell me what I am missing.

+4
c ++ qt opengl qmake
source share
1 answer

You need to add the .pro file

 LIBS += opengl32.lib 

if you are using Visual Studio to properly build the OpenGL libraries.

Here you can find more information:

http://doc.qt.io/qt-5/windows-requirements.html

+7
source share

All Articles