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

3

18

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.

Dhaulagiri answered 3/8, 2017 at 19:24 Comment(2)
I believe glad.h is not in a default OpenGL install. Do you have it somewhere in your computer? I'd guess you don't, and you'd need to get it from somewhere...Semiliquid
glad.h is part of Multi-Language GL/GLES/EGL/GLX/WGL Loader-GeneratorConfinement
D
4

GLAD is a function loader for OpenGL. This tutorial explains how to set it up.

The tutorial explains the purpose of GLAD:

Since there are many different versions of OpenGL drivers, the location of most of its functions is not known at compile-time and needs to be queried at run-time.

Setup of GLAD involves using a web server to generate source and header files specific to your GL version, extensions, and language. The source and header files are then placed in your project's src and include directories.

Dhaulagiri answered 3/8, 2017 at 21:53 Comment(2)
"specific to your graphics drivers" No, because that would mean no portability at all. The web server basically lets you choose a GL version, extensions, and a language, and that's all.Doddering
thanks @HolyBlackCat, I updated the answer to reflect that.Dhaulagiri
O
3

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:

gcc glfw_ex2.c -lglfw -lGLESv2 -lm

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

Outroar answered 25/3, 2021 at 11:31 Comment(0)
G
0

I suggested you push F5 to run-and-debug the program in VSCode,you can try execute the command "make run" if you change the file named "mingw32-make.exe" to "make.exe" in your directory which exists the file "makefile"

Gripsack answered 8/11, 2023 at 7:11 Comment(1)
How is the program going to run, if the compilation fails?Citronella

© 2022 - 2024 — McMap. All rights reserved.