GLEW and Qt5 redefinition of headers
Asked Answered
R

2

10

So,

After upgrading our prject to Qt5 we are experiencing issues with glew. The app links a library that needs glew to work, and that works fine when using the library in non Qt apps.

Now though we are linking the library into a qt app and rendering into a glwidget. This used to work but now it doesnt. We get a huge array of errors that mostly say "redefinition of" something. Here's some examples:

 1>c:\glew-1.9.0\include\gl\glew.h(275): error C2371: 'GLdouble' : redefinition; different basic types
1>          c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\qtgui\qopengl.h(71) : see declaration of 'GLdouble'
1>c:\glew-1.9.0\include\gl\glew.h(630): warning C4005: 'GL_DOUBLE' : macro redefinition
1>          c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\qtgui\qopengl.h(68) : see previous definition of 'GL_DOUBLE'
1>c:\glew-1.9.0\include\gl\glew.h(1655): error C2371: 'GLintptr' : redefinition; different basic types
1>          c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\gles2\gl2.h(38) : see declaration of 'GLintptr'
1>c:\glew-1.9.0\include\gl\glew.h(1656): error C2371: 'GLsizeiptr' : redefinition; different basic types
1>          c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\gles2\gl2.h(39) : see declaration of 'GLsizeiptr'
1>c:\glew-1.9.0\include\gl\glew.h(1707): warning C4005: 'GL_BLEND_EQUATION_RGB' : macro redefinition
1>          c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\gles2\gl2.h(96) : see previous definition of 'GL_BLEND_EQUATION_RGB'
1>c:\glew-1.9.0\include\gl\glew.h(11533): warning C4005: 'GL_COVERAGE_SAMPLES_NV' : macro redefinition

You get the idea. Anyway how can I stop Qt including its gl stuff so glew can work by itself?

As you can see gles is being a problem, so I was directed to use this:

#define QT_NO_OPENGL_ES_2

But this has no effect at all. There are other errors that don't reference gles like these:

    1>c:\glew-1.9.0\include\gl\glew.h(275): error C2371: 'GLdouble' : redefinition; different basic types
1>          c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\qtgui\qopengl.h(71) : see declaration of 'GLdouble'
1>c:\glew-1.9.0\include\gl\glew.h(630): warning C4005: 'GL_DOUBLE' : macro redefinition
1>          c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\qtgui\qopengl.h(68) : see previous definition of 'GL_DOUBLE'
1>c:\glew-1.9.0\include\gl\glew.h(1655): error C2371: 'GLintptr' : redefinition; different basic types
1>          c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\gles2\gl2.h(38) : see declaration of 'GLintptr'
1>c:\glew-1.9.0\include\gl\glew.h(1656): error C2371: 'GLsizeiptr' : redefinition; different basic types
1>          c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\gles2\gl2.h(39) : see declaration of 'GLsizeiptr'
1>c:\glew-1.9.0\include\gl\glew.h(1707): warning C4005: 'GL_BLEND_EQUATION_RGB' : macro redefinition
1>          c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\gles2\gl2.h(96) : see previous definition of 'GL_BLEND_EQUATION_RGB'
1>c:\glew-1.9.0\include\gl\glew.h(11533): warning C4005: 'GL_COVERAGE_SAMPLES_NV' : macro redefinition
1>          c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\qtgui\qopengles2ext.h(530) : see previous definition of 'GL_COVERAGE_SAMPLES_NV'

Hopefully you can help!

Rammish answered 15/6, 2013 at 11:23 Comment(0)
R
4

After a day of screwing around I have a solution!

In order to be cross platform Qt seems to have set OpenGLES to a high priority than desktop openGL.

THe solution to this is to build Qt from source code suing the setting -opengl desktop before you build. Something like this:

configure -debug-and-release -opengl desktop

Then use nmake to build and it works fine!

Rammish answered 15/6, 2013 at 16:28 Comment(2)
Can you explain how to do this in Qt? Or a more verbose answer on how you did this?Haiduk
Worked for me. I was seeing a similar problem building for VS2012 with 32-bit desktop EXEs and OpenGL (instead of ANGLE). My full command line to build the source from the VS2012 command prompt was: configure -prefix c:\Qt\Qt5.1.1\5.1.1\msvc2012_opengl -mp -debug-and-release -opengl desktop -c++11 -opensource -D _CRT_SECURE_NO_WARNINGS -nomake examples -skip qtwebkit-examples && nmake && nmake installTetartohedral
D
4

My personal approach with using OpenGL with Qt is to separate all OpenGL related part from Qt class implementation. In the Qt part I then just call into the framework neutral written OpenGL code through regular C or C++ interfaces using standard types. Since the actual OpenGL code makes no references to Qt then, it doesn't have to include Qt headers, avoiding problems like yours.

Disease answered 15/6, 2013 at 12:35 Comment(2)
I actually do need qt though since I use the QGLWidget to render on. I've actually fixed it by rebuilding Qt. I will post a proper answer.Rammish
@DavidC: You can still use a QGLWidget. Put your OpenGL code into a separate compilation unit and header (like glrenderer.h glrenderer.cc) that doesn't use Qt and in your QGLwidgt derived class call the functions from the glrenderer.cc compilation unit.Disease
R
4

After a day of screwing around I have a solution!

In order to be cross platform Qt seems to have set OpenGLES to a high priority than desktop openGL.

THe solution to this is to build Qt from source code suing the setting -opengl desktop before you build. Something like this:

configure -debug-and-release -opengl desktop

Then use nmake to build and it works fine!

Rammish answered 15/6, 2013 at 16:28 Comment(2)
Can you explain how to do this in Qt? Or a more verbose answer on how you did this?Haiduk
Worked for me. I was seeing a similar problem building for VS2012 with 32-bit desktop EXEs and OpenGL (instead of ANGLE). My full command line to build the source from the VS2012 command prompt was: configure -prefix c:\Qt\Qt5.1.1\5.1.1\msvc2012_opengl -mp -debug-and-release -opengl desktop -c++11 -opensource -D _CRT_SECURE_NO_WARNINGS -nomake examples -skip qtwebkit-examples && nmake && nmake installTetartohedral

© 2022 - 2024 — McMap. All rights reserved.