Reputation: 5181
I am trying to take the Qt example from the Qt-distribution in examples/gui/openglwindow/ and make it compile/run with CMake on Windows. However, when compiling, it fails with a bunch of “error LNK2019: unresolved external symbol __imp_glClear”
I can fix that by manually adding C:\Qt_install\lib\libGLESv2d.lib to the linker path, however, that’s obviously not how CMake should work.
My CMakeLists is very simple:
PROJECT( oglwin )
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12 )
cmake_policy(SET CMP0020 NEW) # for Qt: auto-link to qtmain.lib
set(CMAKE_AUTOMOC ON)
find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)
SET(SOURCE
main.cpp
openglwindow.cpp
)
SET(HEADERS
openglwindow.h
)
ADD_EXECUTABLE( oglwin ${SOURCE} ${HEADERS} )
TARGET_LINK_LIBRARIES( oglwin Qt5::Core Qt5::Gui )
Now as I mentioned before, my expectation would be that this automatically links to libGLESv2.lib (or libGLESv2d.lib), as I am using a Qt-build built with ANGLE. (For that matter, I guess when on the desktop/opengl build, it should link to GL.lib [or whatever the system openGL lib is called]).
Possibly in my case, it should also link to C:\Qt_install\lib\libEGLd.lib.
There are a few related topics around, for example this: https://bugreports.qt-project.org/browse/QTBUG-29132 (where it says “fixed”), and one can follow that to gitorious: https://codereview.qt-project.org/#change,53857
So basically what should happen is that QtGui automatically links to its correct OpenGL back-end, whatever that may be (desktop OpenGL, Angle/GLESv2), it says in the bugreport there that it's able to deduce which back-end to use from the installed Qt distribution.
Apparently what I’m trying to do should work, but it doesn’t. Am I doing something wrong?
Upvotes: 1
Views: 2134
Reputation: 5181
The solution was as follows:
It was coupled with a Qt bug that is now fixed, but it was also necessary to add ${Qt5Gui_EGL_LIBRARIES}
and ${Qt5Gui_OPENGL_LIBRARIES}
to target_link_libraries
.
That makes Qt find the correct OpenGL dependency.
Upvotes: 1