GLEW和Qt5重新定义标题

时间:2013-06-15 11:23:36

标签: qt opengl glew

所以,

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

现在虽然我们将库链接到qt应用程序并渲染成glwidget。这曾经工作,但现在它没有。我们得到了大量错误,主要是说“重新定义”某些东西。以下是一些例子:

 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

你明白了。无论如何我怎么能阻止Qt包括它的gl东西,所以glew可以自己工作?

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

#define QT_NO_OPENGL_ES_2

但这根本没有效果。还有其他错误没有引用像这样的gles:

    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'

希望你能帮忙!

2 个答案:

答案 0 :(得分:4)

我在Qt中使用OpenGL的个人方法是将所有与OpenGL相关的部分与Qt类实现分开。在Qt部分我然后使用标准类型通过常规C或C ++接口调用框架中性编写的OpenGL代码。由于实际的OpenGL代码没有引用Qt,因此它不必包含Qt头,避免像你这样的问题。

答案 1 :(得分:4)

经过一天的拧紧后,我有一个解决方案!

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

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

configure -debug-and-release -opengl desktop

然后使用nmake构建,它工作正常!