Reputation: 3278
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.
Upvotes: 20
Views: 64695
Reputation: 375
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
Upvotes: 5
Reputation: 7
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"
Upvotes: -1
Reputation: 3278
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.
Upvotes: 3