Installing Cub3D
This guide will walk you through setting up all dependencies and building Cub3D from source.System Requirements
Operating System
- Linux (Ubuntu, Debian, Fedora, or similar)
- X11 Window System (X.Org)
Build Tools
- GCC or compatible C compiler
- Make build system
- Git for cloning repositories
Required Libraries
Install X11 Development Libraries
These libraries are required for MiniLibX to create windows and handle graphics:
Ubuntu/Debian
Fedora/RHEL
Arch Linux
Install Math Library
The math library is used for trigonometric calculations in raycasting:
Most Linux distributions include
libm by default, but the development headers may need to be installed separately.Building Dependencies
Cub3D depends on two libraries that must be built alongside the project:MiniLibX
MiniLibX is a simple graphics library for creating windows and rendering pixels. The project expects it in theminilibx-linux/ directory.
The Makefile (
Makefile:34-35) automatically builds MiniLibX when you run make all, so manual building is optional.Libft
Libft is a custom C standard library implementation. The project expects it in thelibft/ directory.
Build Libft
Like MiniLibX, Libft is automatically built by the main Makefile (
Makefile:31-32).Building Cub3D
Build the Project
The Makefile handles all dependencies automatically:This command will:
- Build MiniLibX (
libmlx.a) - Build Libft (
libft.a) - Compile all Cub3D source files
- Link everything into the
cub3dexecutable
The compiler flags used are:
-Wall -Wextra -Werror- Enable all warnings and treat them as errors-O3- Maximum optimization for performance-g -g3- Include debug symbols
Build Targets
The Makefile provides several useful targets:| Command | Description |
|---|---|
make or make all | Build the complete project |
make clean | Remove object files (.o) |
make fclean | Remove object files and the executable |
make re | Rebuild everything from scratch |
Troubleshooting
Error: libmlx.a not found
Error: libmlx.a not found
This means MiniLibX wasn’t built successfully. Try:If that fails, check that X11 development libraries are installed.
Error: X11/X.h not found
Error: X11/X.h not found
Install the X11 development headers:
Compilation warnings or errors
Compilation warnings or errors
The project uses strict compilation flags (
-Wall -Wextra -Werror). Common issues:- Unused variables: Remove or comment them out
- Implicit declarations: Check function prototypes in
cub3.h - Type mismatches: Ensure proper casting, especially with MLX functions
Linking errors with -lm
Linking errors with -lm
The math library must be linked. Verify the Makefile includes
-lm in the linking step:Verification
After successful installation, verify everything works:If a window opens with a 3D view, installation is complete! Press
ESC to close the window.Next Steps
Quick Start Guide
Learn how to run Cub3D and navigate the 3D environment