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.
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.
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.
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With