Update: Wednesday 19 February 2025
### This applies only if the Python script is NOT used and you want to manually include GLAD ###
Most libraries (not all) are located in system directories.
For this reason, the code typically refers to GLAD installed in the system:
#include <glad/glad.h>
However, the files downloaded from https://glad.dav1d.de/ are stored in our local folders. So, when compiling the project, GLAD files are not found.
Because they are not in the system directories; they remain where we downloaded them!
When the files are in system directories, we must use angle brackets < >
Example:
#include <glad/glad.h>
If the files are in a custom folder (not a system directory), we must use double quotes " "
Example:
#include "folder/glad/glad.h"
The .zip
file generated from https://glad.dav1d.de/ contains the same files as if we had downloaded the include
and src
folders separately.
These two folders also appear in the list of available downloads after generating the files by pressing the GENERATE
button at the bottom of the webpage.
### This is NOT the compatibility profile, only the OpenGL core ###
Download the .zip
file or the individual folders, but not everything!
Once downloaded:
1. In the same location as your main.cpp
file, copy the glad.c
file from the src
folder and then delete the src
folder (it is no longer needed since we have copied glad.c
into our project).
2. Also, in the same location as main.cpp
, copy the entire include
folder (which contains the KHR
and glad
subfolders).
Make sure that at the top of your main.cpp
file, outside the main( )
function, you include the GLAD header using double quotes " "
instead of < >
Open main.cpp
and update the #include
statement to use the correct path:
#include "include/glad/glad.h"
In some cases, you may also need to modify the #include
directive inside glad.c
This ensures that glad.c
can find the correct location of glad.h
, also using double quotes " "
instead of < >
Open glad.c
and update the #include
statement.
Original:
#include <glad/glad.h>
Modified:
#include "include/glad/glad.h"
To create the GLAD library file, compile glad.c
using clang
.
If clang
is not installed, you will need to install it before proceeding.
To compile, execute the following command in a terminal:
clang -c glad.c
After compilation, an object file (glad.o
) will be created.
Next, use the ar
command to generate a static .a
library file. If ar
is not installed, you will need to install it.
ar rcs libglad.a glad.o
The ar
command is used here to create a static library so that the linker does not dynamically search for the library in system directories.
The static .a
file should be manually placed inside the lib
folder of our project.
Folder Structure
The following folders and files should be in the same location:
PROJECT
include
(folder)lib
(folder)main.cpp
(file)glad.c
(file)Compilation Example
To compile the project, use the following command:
g++ main.cpp glad.c -o output -Lfolder -lglad -lglfw3
-o output
option specifies the name of the executable file that will be created after compilation (in this case, output
). You can change output
to any other name, but avoid spaces or special characters.-L
option specifies the path where the lib
folder is located.-l
option specifies the libraries used in the project (one -l
flag per library).Running the Program
To execute the compiled program, run the following command in the terminal:
./output