glew.h 和 glext.h 之间不兼容的函数原型

Gil*_*les 3 c++ opengl glew

我正在尝试使用 glew.h 和 glext.h 编译一些代码。这是一个最小的例子:

#include <GL/glew.h>
//#include <GL/gl.h> // commenting it doesn't change anything
#include <GL/glext.h>

int main(){
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

由于不同的函数原型,我有 6 个编译时错误。第一个是:

In file included from main.cpp:3:0:
/usr/include/GL/glext.h:12306:105: error: conflicting declaration ‘typedef void (* PFNGLFRAGMENTLIGHTFVSGIXPROC)(GLenum, GLenum, const GLfloat*)’
 typedef void (APIENTRYP PFNGLFRAGMENTLIGHTFVSGIXPROC) (GLenum light, GLenum pname, const GLfloat *params);
                                                                                                         ^
In file included from main.cpp:1:0:
/usr/include/GL/glew.h:16092:28: note: previous declaration as ‘typedef void (* PFNGLFRAGMENTLIGHTFVSGIXPROC)(GLenum, GLenum, GLfloat*)’
 typedef void (GLAPIENTRY * PFNGLFRAGMENTLIGHTFVSGIXPROC) (GLenum light, GLenum pname, GLfloat* params);
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Run Code Online (Sandbox Code Playgroud)

glew.h:16092:

typedef void (GLAPIENTRY * PFNGLFRAGMENTLIGHTFVSGIXPROC) (GLenum light, GLenum pname, GLfloat* params);
Run Code Online (Sandbox Code Playgroud)

glext.h:12306:

typedef void (APIENTRYP PFNGLFRAGMENTLIGHTFVSGIXPROC) (GLenum light, GLenum pname, const GLfloat *params);
Run Code Online (Sandbox Code Playgroud)

不同之处在于 * params的常量性。

我在 Ubuntu 18.04.5 LTS 上使用 mesa 20.0.8、glew 2.0.0-5 和 gcc 7.5.0(我应该升级到 Ubuntu 20 吗?)。

Nic*_*las 6

我正在尝试使用 glew.h 和 glext.h 编译一些代码。

不要那样做。这是两种不同的工具,它们都做同样的事情。它们不打算相互兼容,也不希望在另一个(在同一个源文件中)存在的情况下工作。

您要么使用 GLEW,要么通过 glext.h 手动加载函数指针。选一个。