Skip to main content

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:
CC = g++
CFLAGS = -Wall -Wextra -std=c++17
LIBS = -lraylib -lenet -lGL -lm -lpthread -ldl -lrt -lX11

SRC = src/main.cpp
OUT = build/game

all: $(OUT)

$(OUT): $(SRC)
	@mkdir -p build
	$(CC) $(CFLAGS) $(SRC) -o $(OUT) $(LIBS)

run: all
	./$(OUT)

clean:
	rm -rf build

.PHONY: all run clean

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)
CC = g++
CFLAGS = -Wall -Wextra -std=c++17
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:
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)
Linked via: -lraylib
UDP-based networking for multiplayer functionality.Features:
  • Host/client architecture
  • Reliable packet transmission
  • Connection management
  • Low-latency communication
Linked via: -lenet
Required by raylib for hardware-accelerated rendering.Linked via: -lGL
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

LIBS = -lraylib -lenet -lGL -lm -lpthread -ldl -lrt -lX11
On some systems, you may need to install development packages: libraylib-dev, libenet-dev, libgl1-mesa-dev, libx11-dev

Build targets

all (default target)

Builds the game executable:
make all
# or simply
make
This target:
  1. Creates the build/ directory if it doesn’t exist
  2. Compiles src/main.cpp with specified flags
  3. Links all required libraries
  4. Outputs executable to build/game
The compilation command executed:
g++ -Wall -Wextra -std=c++17 src/main.cpp -o build/game -lraylib -lenet -lGL -lm -lpthread -ldl -lrt -lX11

run

Builds and immediately runs the game:
make run
This target:
  1. Depends on the all target (ensures game is built)
  2. Executes ./build/game
Equivalent to:
make all && ./build/game

clean

Removes all build artifacts:
make clean
Deletes the entire 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

  1. Preprocessing: Resolves #include directives, expands macros
    • #include "raylib.h" - Graphics framework
    • #include <bits/stdc++.h> - Standard library (non-portable, includes all STL)
    • #include <enet/enet.h> - Networking
  2. Compilation: Converts C++ source to object code
    • Applies -Wall -Wextra warning checks
    • Uses C++17 language features
  3. Linking: Combines object code with libraries
    • Links raylib for graphics/audio
    • Links ENet for networking
    • Links system libraries
  4. Output: Produces build/game executable

Directory structure

project/
├── src/
│   └── main.cpp        # Main source file
├── assets/             # Game assets (textures, audio)
│   ├── island.png
│   ├── tree.png
│   ├── cursor.png
│   ├── self_char.png
│   └── music/
│       └── death.mp3
├── build/              # Generated by Makefile
│   └── game           # Compiled executable
└── Makefile           # Build configuration

PHONY targets

.PHONY: all run clean
Declares 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:
make clean && make
Build and run:
make run
Check for warnings:
make all 2>&1 | grep warning
Verbose build (see full commands):
make all V=1
If you encounter linking errors, ensure all dependencies are installed. On Ubuntu/Debian: sudo apt install libraylib-dev libenet-dev libgl1-mesa-dev libx11-dev

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
Missing ENet: If you get “enet/enet.h: No such file or directory”
  • Install: sudo apt install libenet-dev
C++17 not supported: If compiler errors mention C++17 features
  • Update g++ to version 7.0 or higher
  • Check version: g++ --version
Linking errors with -lX11: Missing X11 development files
  • Install: sudo apt install libx11-dev

Build docs developers (and LLMs) love