GLEW和Qt5头文件的重新定义



所以,

在我们的项目升级到Qt5之后,我们遇到了glow问题。该应用程序链接了一个需要glow才能工作的库,并且在非Qt应用程序中使用该库时可以正常工作。

现在我们将库链接到qt应用程序并渲染到glwidget中。这在过去是可行的,但现在不行了。我们得到大量的错误,大多是"重新定义"的东西。下面是一些例子:

 1>c:glew-1.9.0includeglglew.h(275): error C2371: 'GLdouble' : redefinition; different basic types
1>          c:qtqt5.0.25.0.2msvc2012_64includeqtguiqopengl.h(71) : see declaration of 'GLdouble'
1>c:glew-1.9.0includeglglew.h(630): warning C4005: 'GL_DOUBLE' : macro redefinition
1>          c:qtqt5.0.25.0.2msvc2012_64includeqtguiqopengl.h(68) : see previous definition of 'GL_DOUBLE'
1>c:glew-1.9.0includeglglew.h(1655): error C2371: 'GLintptr' : redefinition; different basic types
1>          c:qtqt5.0.25.0.2msvc2012_64includegles2gl2.h(38) : see declaration of 'GLintptr'
1>c:glew-1.9.0includeglglew.h(1656): error C2371: 'GLsizeiptr' : redefinition; different basic types
1>          c:qtqt5.0.25.0.2msvc2012_64includegles2gl2.h(39) : see declaration of 'GLsizeiptr'
1>c:glew-1.9.0includeglglew.h(1707): warning C4005: 'GL_BLEND_EQUATION_RGB' : macro redefinition
1>          c:qtqt5.0.25.0.2msvc2012_64includegles2gl2.h(96) : see previous definition of 'GL_BLEND_EQUATION_RGB'
1>c:glew-1.9.0includeglglew.h(11533): warning C4005: 'GL_COVERAGE_SAMPLES_NV' : macro redefinition

你懂的。无论如何,我怎么能停止Qt包括它的gl的东西,让辉光可以自己工作?

正如你所看到的,这是一个问题,所以我被指示使用这个:

#define QT_NO_OPENGL_ES_2

但是这完全没有效果。还有一些没有引用的错误,比如:

    1>c:glew-1.9.0includeglglew.h(275): error C2371: 'GLdouble' : redefinition; different basic types
1>          c:qtqt5.0.25.0.2msvc2012_64includeqtguiqopengl.h(71) : see declaration of 'GLdouble'
1>c:glew-1.9.0includeglglew.h(630): warning C4005: 'GL_DOUBLE' : macro redefinition
1>          c:qtqt5.0.25.0.2msvc2012_64includeqtguiqopengl.h(68) : see previous definition of 'GL_DOUBLE'
1>c:glew-1.9.0includeglglew.h(1655): error C2371: 'GLintptr' : redefinition; different basic types
1>          c:qtqt5.0.25.0.2msvc2012_64includegles2gl2.h(38) : see declaration of 'GLintptr'
1>c:glew-1.9.0includeglglew.h(1656): error C2371: 'GLsizeiptr' : redefinition; different basic types
1>          c:qtqt5.0.25.0.2msvc2012_64includegles2gl2.h(39) : see declaration of 'GLsizeiptr'
1>c:glew-1.9.0includeglglew.h(1707): warning C4005: 'GL_BLEND_EQUATION_RGB' : macro redefinition
1>          c:qtqt5.0.25.0.2msvc2012_64includegles2gl2.h(96) : see previous definition of 'GL_BLEND_EQUATION_RGB'
1>c:glew-1.9.0includeglglew.h(11533): warning C4005: 'GL_COVERAGE_SAMPLES_NV' : macro redefinition
1>          c:qtqt5.0.25.0.2msvc2012_64includeqtguiqopengles2ext.h(530) : see previous definition of 'GL_COVERAGE_SAMPLES_NV'

希望你能帮忙!

我个人使用OpenGL与Qt的方法是将所有OpenGL相关的部分与Qt类实现分开。在Qt部分,我只是通过使用标准类型的常规C或c++接口调用框架中立的OpenGL代码。因为实际的OpenGL代码没有引用Qt,所以它不需要包含Qt头文件,避免了像你这样的问题。

折腾了一天,我有办法了!

为了跨平台,Qt似乎将OpenGLES设置为比桌面openGL更高的优先级。

这个问题的解决方案是在构建之前使用设置-opengl desktop从源代码构建Qt。像这样:

configure -debug-and-release -opengl desktop

然后使用nmake来构建,它工作得很好!

最新更新