【问题标题】:GLEW and Qt5 redefinition of headersGLEW 和 Qt5 重新定义标题
【发布时间】:2013-06-11 23:10:18
【问题描述】:

所以,

将我们的项目升级到 Qt5 后,我们遇到了 glew 问题。该应用程序链接了一个需要 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

但这根本没有效果。还有其他不引用这些文件的错误:

    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'

希望你能帮忙!

【问题讨论】:

    标签: qt opengl glew


    【解决方案1】:

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

    【讨论】:

    • 我实际上确实需要 qt,因为我使用 QGLWidget 进行渲染。我实际上已经通过重建 Qt 来修复它。我会发布一个正确的答案。
    • @DavidC:你仍然可以使用 QGLWidget。将您的 OpenGL 代码放入不使用 Qt 的单独编译单元和标头(如 glrenderer.h glrenderer.cc)中,并在您的 QGLwidgt 派生类中调用来自 glrenderer.cc 编译单元的函数。
    【解决方案2】:

    经过一天的折腾,我有一个解决方案!

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

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

    configure -debug-and-release -opengl desktop
    

    然后使用nmake构建,就可以正常使用了!

    【讨论】:

    • 你能解释一下如何在 Qt 中做到这一点吗?或者关于你是如何做到这一点的更详细的答案?
    • 为我工作。我看到使用 32 位桌面 EXE 和 OpenGL(而不是 ANGLE)构建 VS2012 的类似问题。我从 VS2012 命令提示符构建源代码的完整命令行是: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 install
    猜你喜欢
    • 1970-01-01
    • 2021-12-23
    • 1970-01-01
    • 2013-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-05
    • 2013-12-27
    相关资源
    最近更新 更多