<glad/glad.h>: No such file or directory

Viewed 38091

I'm following this tutorial to learn OpenGL, but I'm having trouble compiling since the compiler can't find one of the header files.

This is the file I'm trying to compile:

#include <glad/glad.h>
#include <GLFW/glfw3.h>

int main() {    
  return 0;
}

To compile, I'm using

$ gcc -o sandbox sandbox.cpp -lGL -lGLU -lglut

and I get the following error:

sandbox.cpp:1:23: fatal error: glad/glad.h: No such file or directory
#include <glad/glad.h>
                   ^
compilation terminated.

I followed the first two sections of this wiki to install OpenGL and libraries.

I think the problem is either the wrong compile command or a flaw in my OpenGL installation.

2 Answers

If you are looking at this simple GLFW example you can remove the glad/gl.h include, and the

gladLoadGL(glfwGetProcAddress);

line further down. If you are on linux, ubuntu for example, you don't need glad, just add these 2 headers instead:

#include <GLES2/gl2.h>
#include <EGL/egl.h>

If the example is saved as glfw_ex2.c you can compile it at the command line like this:

g++ glfw_ex2.c -lglfw -lGLESv2

Of course, linmath.h must be present in the same directory for this example.

If anything is missing, you can install it like this and try compiling again:

sudo apt install libglfw3-dev libgles2-mesa-dev libegl1-mesa-dev

sudo apt install build-essential

then run it like this:

./a.out

Screenshot from the glfw example on ubuntu

Related