Hi,
I have been wrestling with GLAD on Linux now for a number of weeks but cannot seem to escape
In file included from base/inc/core/shader_manager.h:4:0,
from base/src/main.cpp:17:
base/inc/glad/glad.h:577:2: error: #error OpenGL header already included, remove this include, glad already provides it
#error OpenGL header already included, remove this include, glad already provides it
For this specific branch of my project. I have only included glad in mesh_generator.h and shader_manager.h, so what am I doing wrong? I understand that this project is a little complicated, but would like to know what is going on.
Thank you.
BTW, I totally understand that it is stating that I have included the OpenGL header that GLAD provides, but this very specifically breaks code.
The error means that the compiler finds a gl.h
include before the glad.h
include, which can be through any dependency, most likely GLFW.
A simple include graph:
Your main.cpp
includes core/game_superclass.h
which then includes core/poll_keyboard.h
very early, which has a dependency on glfw, which then includes gl.h
, later on you will include glad, but by this time gl.h
was already included (Fuck yeah C!).
I defined GLFW_INCLUDE_NONE
in your main.cpp
(it makes glfw not include g.h
publically), but then compilation fails because of missing types in core/camera_data.h
.
Probably easiest fix is including glad at the very top of core/game_superclass.h
, imo a better way of handling this include mess is creating a header file which includes gl for you and one which includes glfw for you, in the first you include second in the latter you either define the GLFW_INCLUDE_NONE
or include your gl header before glfw. And whenever you need gl or glfw you include either of these headers.
Ah I forgot:
diff --git a/Makefile b/Makefile
index 2f3ae96..178e42e 100755
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
#Libs to link against
-GRAPHICSLIBS = -lX11 -lXxf86vm -lXrandr -lXi -lGL -lGLU -lGLEW
+GRAPHICSLIBS = -lX11 -lXxf86vm -lXrandr -lXi -lGL -lGLU -ldl
PTHREADLIBS = -lm -lpthread
RMF = rm -f
EXE = avgame
diff --git a/base/inc/core/game_superclass.h b/base/inc/core/game_superclass.h
index 298e79b..10fba05 100644
--- a/base/inc/core/game_superclass.h
+++ b/base/inc/core/game_superclass.h
@@ -1,6 +1,7 @@
#ifndef _AVGAME_SUPER_
#define _AVGAME_SUPER_
+#include <glad/glad.h>
#include <core/poll_mouse.h>
#include <core/poll_keyboard.h>
#include <core/game_debug.h>
The diff which makes your project compile.
Thank you so much @Dav1dde ! This is great! The detailed explanation is also appreciated. :+1:
Most helpful comment
The error means that the compiler finds a
gl.h
include before theglad.h
include, which can be through any dependency, most likely GLFW.A simple include graph:
Your
main.cpp
includescore/game_superclass.h
which then includescore/poll_keyboard.h
very early, which has a dependency on glfw, which then includesgl.h
, later on you will include glad, but by this timegl.h
was already included (Fuck yeah C!).I defined
GLFW_INCLUDE_NONE
in yourmain.cpp
(it makes glfw not includeg.h
publically), but then compilation fails because of missing types incore/camera_data.h
.Probably easiest fix is including glad at the very top of
core/game_superclass.h
, imo a better way of handling this include mess is creating a header file which includes gl for you and one which includes glfw for you, in the first you include second in the latter you either define theGLFW_INCLUDE_NONE
or include your gl header before glfw. And whenever you need gl or glfw you include either of these headers.