Projects that use the QtOpenGL fail to link to gl calls, but only on Windows (Linux is happy). The MSVC 2008 error messages for the following minimal case project are:
1>gllink.obj : error LNK2019: unresolved external symbol __imp__glLoadIdentity@0 referenced in function "protected: virtual void __thiscall ImageWidget::initializeGL(void)" (?initializeGL@ImageWidget@@MAEXXZ)
1>gllink.obj : error LNK2019: unresolved external symbol __imp__glMatrixMode@4 referenced in function "protected: virtual void __thiscall ImageWidget::initializeGL(void)" (?initializeGL@ImageWidget@@MAEXXZ)
1>gllink.exe : fatal error LNK1120: 2 unresolved externals
These errors disappear when I manually add "opengl32.lib" to the "Additional Dependencies" list, but I believe this should not be necessary, since this should either be done by FindQt4.cmake, or should be taken care of by the dependency of QtOpenGL on opengl32. Of course, I must be mistaken, so I would really appreciate some input on how to properly fix this project.
gllink.cpp
#include <QtOpenGL>
#include <QWidget>
class ImageWidget : public QGLWidget
{
public:
ImageWidget(QWidget* parent = 0) :
QGLWidget(parent)
{
}
protected:
void initializeGL()
{
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
}
};
int main()
{
ImageWidget w;
return 0;
}
CMakeLists.txt
PROJECT( gllink )
CMAKE_MINIMUM_REQUIRED( VERSION 2.8 )
FIND_PACKAGE( Qt4 4.6.0 REQUIRED COMPONENTS QtCore QtGui QtOpenGL )
INCLUDE( ${QT_USE_FILE} )
ADD_EXECUTABLE( gllink gllink.cpp )
TARGET_LINK_LIBRARIES( gllink ${QT_LIBRARIES} )