Overview
Wizard Duel uses GNU Make for build automation and g++ as the C++ compiler. The build system is defined in a simple Makefile with three main targets.Makefile structure
The complete Makefile:Compiler configuration
Compiler and flags
Compiler: g++ (GNU C++ Compiler) Flags:-Wall: Enable all common warnings-Wextra: Enable extra warning messages beyond -Wall-std=c++17: Use C++17 standard (required for features like structured bindings and std::filesystem)
The C++17 standard is essential for this project as it uses modern C++ features and standard library components.
Dependencies
The game requires the following libraries:raylib - Game framework
raylib - Game framework
Provides graphics, audio, and input handling.Key features used:
- Window management (
InitWindow,CloseWindow) - 2D camera system (
Camera2D,BeginMode2D) - Texture loading and rendering
- Audio device and sound playback
- Input detection (keyboard, mouse)
-lraylibENet - Networking library
ENet - Networking library
UDP-based networking for multiplayer functionality.Features:
- Host/client architecture
- Reliable packet transmission
- Connection management
- Low-latency communication
-lenetOpenGL - Graphics rendering
OpenGL - Graphics rendering
Required by raylib for hardware-accelerated rendering.Linked via:
-lGLSystem libraries
System libraries
Standard Linux system libraries:
-lm: Math library (sqrt, atan2, trigonometric functions)-lpthread: POSIX threads for concurrent operations-ldl: Dynamic linking loader-lrt: Real-time extensions-lX11: X Window System for Linux display
Complete linking command
Build targets
all (default target)
Builds the game executable:- Creates the
build/directory if it doesn’t exist - Compiles
src/main.cppwith specified flags - Links all required libraries
- Outputs executable to
build/game
run
Builds and immediately runs the game:- Depends on the
alltarget (ensures game is built) - Executes
./build/game
clean
Removes all build artifacts:build/ directory, including:
- Compiled executable
- Any intermediate files
The clean target is useful when you want a completely fresh build or need to troubleshoot compilation issues.
Build process
Step-by-step compilation
-
Preprocessing: Resolves
#includedirectives, expands macros#include "raylib.h"- Graphics framework#include <bits/stdc++.h>- Standard library (non-portable, includes all STL)#include <enet/enet.h>- Networking
-
Compilation: Converts C++ source to object code
- Applies
-Wall -Wextrawarning checks - Uses C++17 language features
- Applies
-
Linking: Combines object code with libraries
- Links raylib for graphics/audio
- Links ENet for networking
- Links system libraries
-
Output: Produces
build/gameexecutable
Directory structure
PHONY targets
all, run, and clean as phony targets, meaning they’re commands rather than files. This prevents conflicts if files named “all”, “run”, or “clean” exist in the directory.
Common build commands
Fresh build:Troubleshooting
Common issues
Missing raylib: If you get “raylib.h: No such file or directory”- Install raylib development package
- Or build raylib from source and set include path
- Install:
sudo apt install libenet-dev
- Update g++ to version 7.0 or higher
- Check version:
g++ --version
- Install:
sudo apt install libx11-dev