编译时出现 GL3W 错误

Posted

技术标签:

【中文标题】编译时出现 GL3W 错误【英文标题】:GL3W error on compilation 【发布时间】:2015-01-27 23:26:16 【问题描述】:

我正在尝试使用 gl3w 静态编译 opengl 程序,但在执行 g++ -Wall -o Code Code.cpp --static -ldl -lc -lglut -lGL -lGLU 时出现以下错误

Code.cpp: In function ‘void drawScene()’:
Code.cpp:148:15: error: ‘GL_MODELVIEW’ was not declared in this scope
Code.cpp:148:27: error: ‘glMatrixMode’ was not declared in this scope
Code.cpp:149:17: error: ‘glLoadIdentity’ was not declared in this scope
Code.cpp:150:15: error: ‘glPushMatrix’ was not declared in this scope
Code.cpp:155:32: error: ‘glTranslatef’ was not declared in this scope
Code.cpp:156:27: error: ‘glScalef’ was not declared in this scope
Code.cpp:157:28: error: ‘glColor3f’ was not declared in this scope
Code.cpp:167:34: error: ‘glRasterPos3f’ was not declared in this scope
Code.cpp:172:15: error: ‘glPopMatrix’ was not declared in this scope
Code.cpp:210:19: error: ‘glBegin’ was not declared in this scope
Code.cpp:211:29: error: ‘glVertex3f’ was not declared in this scope
Code.cpp:215:9: error: ‘glEnd’ was not declared in this scope
Code.cpp:216:15: error: ‘glPopMatrix’ was not declared in this scope
Code.cpp:236:35: error: ‘glRotatef’ was not declared in this scope
Code.cpp:238:37: error: ‘glColor4f’ was not declared in this scope
Code.cpp:242:14: error: ‘glPopMatrix’ was not declared in this scope
Code.cpp:249:34: error: ‘glColor4f’ was not declared in this scope
Code.cpp:253:18: error: ‘glBegin’ was not declared in this scope
Code.cpp:254:29: error: ‘glVertex3f’ was not declared in this scope
Code.cpp:260:33: error: ‘glColor4f’ was not declared in this scope
Code.cpp:274:8: error: ‘glEnd’ was not declared in this scope
Code.cpp:282:34: error: ‘glColor4f’ was not declared in this scope
Code.cpp:299:34: error: ‘glColor4f’ was not declared in this scope
Code.cpp:323:19: error: ‘glVertex2f’ was not declared in this scope
Code.cpp: In function ‘void drawBox(float)’:
Code.cpp:693:18: error: ‘glBegin’ was not declared in this scope
Code.cpp:694:31: error: ‘glVertex2f’ was not declared in this scope
Code.cpp:698:8: error: ‘glEnd’ was not declared in this scope
Code.cpp:702:37: error: ‘glVertex3f’ was not declared in this scope
Code.cpp: In function ‘void drawLaser(int)’:
Code.cpp:713:28: error: ‘glColor3f’ was not declared in this scope
Code.cpp:714:18: error: ‘glBegin’ was not declared in this scope
Code.cpp:715:30: error: ‘glVertex2f’ was not declared in this scope
Code.cpp:717:8: error: ‘glEnd’ was not declared in this scope
Code.cpp: In function ‘void drawCannon()’:
Code.cpp:723:18: error: ‘glBegin’ was not declared in this scope
Code.cpp:725:30: error: ‘glVertex3f’ was not declared in this scope
Code.cpp:730:8: error: ‘glEnd’ was not declared in this scope
Code.cpp:746:28: error: ‘glColor3f’ was not declared in this scope
Code.cpp: In function ‘void drawSpider(float)’:
Code.cpp:776:25: error: ‘glBegin’ was not declared in this scope
Code.cpp:778:58: error: ‘glVertex2f’ was not declared in this scope
Code.cpp:780:8: error: ‘glEnd’ was not declared in this scope
Code.cpp:784:30: error: ‘glVertex3f’ was not declared in this scope
Code.cpp: In function ‘void initRendering()’:
Code.cpp:822:11: error: ‘GL_COLOR_MATERIAL’ was not declared in this scope
Code.cpp: In function ‘void handleResize(int, int)’:
Code.cpp:830:15: error: ‘GL_PROJECTION’ was not declared in this scope
Code.cpp:830:28: error: ‘glMatrixMode’ was not declared in this scope
Code.cpp:831:17: error: ‘glLoadIdentity’ was not declared in this scope
Code.cpp:833:15: error: ‘GL_MODELVIEW’ was not declared in this scope
Code.cpp: In function ‘void GetOGLPos(int, int)’:
Code.cpp:940:16: error: ‘GL_MODELVIEW_MATRIX’ was not declared in this scope
Code.cpp:941:16: error: ‘GL_PROJECTION_MATRIX’ was not declared in this scope

我在 #include "GL/glut.h" 之前包含了 #include "GL/gl3w.h" 并且还将 gl3w.h 添加到 /usr/include/GL/ 文件夹中。我做错了他们的事吗?

【问题讨论】:

【参考方案1】:

您尝试使用的函数(例如,glBegin()glVertex…() 等)是 OpenGL 兼容性配置文件的一部分。它们不存在于 gl3w 提供的 OpenGL 核心配置文件中。

听起来这可能不是您真正想要的。如果是这样,请不要使用 gl3w。

【讨论】:

我想静态编译opengl代码。他们还有其他可能的方式吗? 我认为这在 Linux 系统上是不可能的(这是我假设你在这里使用的)。 OpenGL 库非常庞大,我认为在某些情况下它们甚至可能是特定于供应商的。

以上是关于编译时出现 GL3W 错误的主要内容,如果未能解决你的问题,请参考以下文章

创建线程时出现编译时错误

在 Flutter 中构建 Streams 时出现编译时错误

编译过程时出现oracle错误

编译动态矩阵时出现file.exe错误

在编译c++代码时出现如下错误: 望速度解答,很急。。谢谢!

提前编译时出现 SystemJS 错误(NgZone 没有提供程序)