Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

opengl

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.

like image 734
dinosaur Avatar asked Aug 03 '17 19:08

dinosaur


People also ask

How do I add glad to Visual Studio?

Add file glad. Go to Visual Studio > Solution Explorer > right click Source Files > click Add > Existing Item ... . In "Add Existing Item - GLFWx64-GLAD-0" wizard, navigate to C: > GL > GLAD > src > glad. c > click glad.

Where do I put glad C file?

cpp" file is, copy the "glad. c" file that is in the "src" folder that we have downloaded and delete the "src" folder (we don't longer need the "src" folder, because we have copied the "glad. c" file inside our project). Also in the same location where our "main.

What is Glew and glad?

Glad is typically used by selecting the necessary extensions in the web interface, downloading the generated source and header files and copying them into your project. GLEW is a library that needs to be installed and is usually added as an dependency in, e.g., CMake.


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

like image 166
jmarina Avatar answered Sep 19 '22 14:09

jmarina


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.

like image 30
dinosaur Avatar answered Sep 16 '22 14:09

dinosaur