make
compiles the source code and runs the executable. make clean
cleans up the compiled file.
This guide will take you through the steps to set up a new OpenGL project on Arch Linux using GLFW for window management and input, and GLAD for OpenGL function loading.
Ensure that your system's package list and installed packages are up-to-date:
sudo pacman -Syu
Install the base-devel
group of packages which includes the gcc compiler, make, and other development tools:
sudo pacman -S base-devel
Mesa is the open-source implementation of OpenGL. Install it with:
sudo pacman -S mesa
GLFW is a library that allows the creation of windows with an OpenGL context and manages input. Install it with:
sudo pacman -S glfw
GLAD is used to load OpenGL functions. Generate the GLAD loader for your OpenGL version using the Glad web service (https://glad.dav1d.de/), then download and include the files in your project.
Create a new directory for your project with the following structure:
project_name/
│
├── include/
│ ├── glad/
│ │ └── glad.h
│ └── KHR/
│ └── khrplatform.h
│
├── src/
│ └── glad.c
│
├── main.cpp
└── Makefile
Create a Makefile
in your project root that compiles your source code:
CC=g++
CFLAGS=-Iinclude
LDFLAGS=-ldl -lglfw
TARGET=learning-opengl
all:
$(CC) main.cpp src/glad.c $(CFLAGS) $(LDFLAGS) -o $(TARGET)
./$(TARGET)
clean:
rm -f $(TARGET)
Remember to replace placeholder values such as project_name
and learning-opengl
with your actual project name and desired executable name. The CC
, CFLAGS
, LDFLAGS
, and TARGET
variables are set for compiling and linking, and should be adjusted if your setup differs.