OpenGL header already included, remove this include, glad already provides it

原因

glad.h中定义了如下宏判断:

#ifdef __gl_h_
#error OpenGL header already included, remove this include, glad already provides it
#endif
#define __gl_h_

如果在#include <glad/glad.h>前面已有__gl_h_的定义,则会报错。

 

解决方法

#include <glad/glad.h>必须放在所有头文件之前(也可以只放在包含__gl_h_的头文件之前,例如glfw3.h)

即使是引用包含#include <glad/glad.h>的头文件,也必须写在其它头文件前面。

 

例子

头文件test.h中引用了<glad/glad.h>,那么#include <glad/glad.h>必须写在其它#include前面。

而main.cpp引用了"test.h",那么#include "test.h"必须写在其它#include前面。

 

posted @ 2022-12-26 15:09  Clotho_Lee  阅读(631)  评论(0)    收藏  举报