> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/korrykatti/game/llms.txt
> Use this file to discover all available pages before exploring further.

# Building the game

> Complete guide to building Wizard Duel from source, including compiler configuration, dependencies, and build targets

## 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:

```makefile theme={null}
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)

```makefile theme={null}
CC = g++
CFLAGS = -Wall -Wextra -std=c++17
```

<Note>
  The C++17 standard is essential for this project as it uses modern C++ features and standard library components.
</Note>

## Dependencies

The game requires the following libraries:

<Accordion title="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)

  Linked via: `-lraylib`
</Accordion>

<Accordion title="ENet - Networking library">
  UDP-based networking for multiplayer functionality.

  Features:

  * Host/client architecture
  * Reliable packet transmission
  * Connection management
  * Low-latency communication

  Linked via: `-lenet`
</Accordion>

<Accordion title="OpenGL - Graphics rendering">
  Required by raylib for hardware-accelerated rendering.

  Linked via: `-lGL`
</Accordion>

<Accordion title="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
</Accordion>

### Complete linking command

```makefile theme={null}
LIBS = -lraylib -lenet -lGL -lm -lpthread -ldl -lrt -lX11
```

<Tip>
  On some systems, you may need to install development packages: `libraylib-dev`, `libenet-dev`, `libgl1-mesa-dev`, `libx11-dev`
</Tip>

## Build targets

### all (default target)

Builds the game executable:

```bash theme={null}
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:

```bash theme={null}
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:

```bash theme={null}
make run
```

This target:

1. Depends on the `all` target (ensures game is built)
2. Executes `./build/game`

Equivalent to:

```bash theme={null}
make all && ./build/game
```

### clean

Removes all build artifacts:

```bash theme={null}
make clean
```

Deletes the entire `build/` directory, including:

* Compiled executable
* Any intermediate files

<Note>
  The clean target is useful when you want a completely fresh build or need to troubleshoot compilation issues.
</Note>

## 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

```makefile theme={null}
.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**:

```bash theme={null}
make clean && make
```

**Build and run**:

```bash theme={null}
make run
```

**Check for warnings**:

```bash theme={null}
make all 2>&1 | grep warning
```

**Verbose build** (see full commands):

```bash theme={null}
make all V=1
```

<Tip>
  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`
</Tip>

## 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`
