Overview
Cub3D can be built natively on Linux and macOS systems. The build process compiles SDL2 from source and sets up all necessary dependencies automatically.Prerequisites
Required Tools
C Compiler
GCC or Clang compiler with C99 support
Build Tools
GNU Make and standard build utilities
ImageMagick
For font generation (optional: can use Docker fallback)
SDL2 Build Dependencies
System libraries for SDL2 compilation
Platform-Specific Dependencies
- Linux
- macOS
Install development packages for SDL2 compilation:
Ubuntu/Debian
Fedora/RHEL
Arch Linux
Building the Project
Standard Build
The default build process handles all dependencies:Run make
- Extract and compile SDL2 from bundled source (lib/SDL2-2.32.8.tar.gz)
- Extract miniaudio header from lib/miniaudio.tar.gz
- Generate font assets from TTF files
- Decrypt and extract Wolf3D assets
- Compile all source files
- Link the final executable
Build Output
Successful compilation produces:- cub3d - Main executable
- obj/ - Compiled object files
- lib/libSDL2.a - Static SDL2 library
- headers/SDL2/ - SDL2 headers
- headers/miniaudio.h - Audio library header
- assets/fonts/ - Generated font bitmap files
- assets/wolf3d/ - Decrypted game assets
Makefile Targets
Primary Targets
Debugging Targets
Cleaning Targets
Asset Targets
Compiler Flags
The build uses these compiler flags:- -Wall -Wextra -Werror: Strict warnings as errors
- -O3: Maximum optimization
- -g: Debug symbols
Platform Detection
The Makefile automatically detects your platform:- Darwin (macOS): Links Apple frameworks
- Linux: Adjusts compiler warnings based on GCC vs Clang
Library Dependencies
SDL2
SDL2 is compiled from source (version 2.32.8) with:miniaudio
The miniaudio single-header library provides audio functionality:- Extracted from: lib/miniaudio.tar.gz
- Placed in: headers/miniaudio.h
System Libraries
- libSDL2: Graphics and input
- libdl: Dynamic linking
- libpthread: Threading support
Troubleshooting
SDL2 compilation fails
SDL2 compilation fails
Ensure you have development headers installed:On macOS, ensure Xcode Command Line Tools are installed:
Linux
Font generation fails
Font generation fails
The fonts.sh script requires ImageMagick. Install it:Or let the script use Docker as a fallback.
Linux
macOS
Permission denied errors
Permission denied errors
Make sure scripts have execute permissions:
Linker errors on macOS
Linker errors on macOS
If you see framework linking errors, update Xcode:
Build Performance
First build takes longer (3-5 minutes) due to SDL2 compilation. Subsequent builds are much faster since SDL2 is cached.
Speeding Up Builds
The Makefile supports parallel compilation:make cdev instead of make clean dev to preserve compiled audio objects.
Next Steps
Creating Maps
Learn how to create custom .cub maps
Controls
Understand keyboard, mouse, and gamepad controls