头文件报错gl.h included before glew.h
时间: 2023-07-19 18:43:31 浏览: 174
这个错误通常是由于头文件引入的顺序不正确所导致的。因为在引入 glew.h 之前必须先引入 OpenGL 的头文件 gl.h。
解决方法是将引入 gl.h 的代码放在引入 glew.h 的代码之前。或者,使用条件编译来检查是否已经定义了 GLEW_NO_GLU 宏,如果已经定义,则不需要引入 gl.h 头文件。
示例代码:
```
#define GLEW_NO_GLU
#include <GL/glew.h>
#ifdef GLEW_NO_GLU
// 不需要引入gl.h
#else
#include <GL/gl.h>
#endif
```
这样就能够避免头文件引入顺序错误的问题了。
相关问题
gl.h included before glew.h
这句话的意思是在包含glew.h之前已经包含了gl.h。这可能会导致一些问题,因为glew.h中也包含了gl.h,如果两个头文件中有相同的定义,就会出现重复定义的错误。为了避免这种情况,应该先包含glew.h,再包含gl.h。
按照上述代码修改后还是会报错gl.h included before glew.h
如果按照上述方法修改仍然出现 `gl.h included before glew.h` 的错误,那么可能是因为你的编译器不支持预编译头文件,或者预编译头文件的设置不正确。
你可以尝试在编译选项中关闭预编译头文件的选项,或者将 `glew.h` 的引入语句放在其他头文件的引入语句之后,例如:
```
#include <stdio.h>
#include <math.h>
#include <fstream>
#include <iostream>
#include <string>//getline
#include <sstream>
#include "stb_image.h"
#include <gl/glaux.h>
#include <vector>
#include <gl/glut.h> // 这里将 glut.h 的引入放在了 glew.h 的引入之后
#include "glew.h"
#pragma comment(lib, "openGL32.lib")
#pragma comment(lib, "glu32.lib")
#pragma comment(lib, "glaux.lib")
```
如果还是不行,可以尝试重新安装 GLEW 库,并将库文件的路径添加到编译器的搜索路径中。