Skip to main content

Installing Cub3D

This guide will walk you through setting up all dependencies and building Cub3D from source.

System Requirements

Cub3D requires a Linux environment with X11 support. It is not compatible with macOS or Windows without modifications.

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

1

Install X11 Development Libraries

These libraries are required for MiniLibX to create windows and handle graphics:
Ubuntu/Debian
sudo apt-get update
sudo apt-get install libx11-dev libxext-dev
Fedora/RHEL
sudo dnf install libX11-devel libXext-devel
Arch Linux
sudo pacman -S libx11 libxext
2

Install Math Library

The math library is used for trigonometric calculations in raycasting:
sudo apt-get install libm-dev
Most Linux distributions include libm by default, but the development headers may need to be installed separately.
3

Install Build Essentials

Ensure you have the basic build tools:
Ubuntu/Debian
sudo apt-get install build-essential
Fedora/RHEL
sudo dnf groupinstall "Development Tools"

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 the minilibx-linux/ directory.
# Navigate to your Cub3D source directory
cd ~/workspace/source

# Clone MiniLibX if not present
if [ ! -d "minilibx-linux" ]; then
  git clone https://github.com/42Paris/minilibx-linux.git
fi
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 the libft/ directory.
Build Libft
# Navigate to libft directory
cd ~/workspace/source/libft

# Build the library
make

# Verify the build
ls -la libft.a
Like MiniLibX, Libft is automatically built by the main Makefile (Makefile:31-32).

Building Cub3D

1

Clone the Repository

git clone <repository-url> ~/workspace/source
cd ~/workspace/source
2

Build the Project

The Makefile handles all dependencies automatically:
make
This command will:
  1. Build MiniLibX (libmlx.a)
  2. Build Libft (libft.a)
  3. Compile all Cub3D source files
  4. Link everything into the cub3d executable
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
3

Verify the Build

Check that the executable was created:
ls -la cub3d
./cub3d
You should see the usage message:
Debes introducir dos argumentos por terminal

Build Targets

The Makefile provides several useful targets:
CommandDescription
make or make allBuild the complete project
make cleanRemove object files (.o)
make fcleanRemove object files and the executable
make reRebuild everything from scratch
# Remove all build artifacts
make fclean

# Rebuild from scratch
make

Troubleshooting

This means MiniLibX wasn’t built successfully. Try:
cd minilibx-linux
make clean
make
If that fails, check that X11 development libraries are installed.
Install the X11 development headers:
sudo apt-get install libx11-dev libxext-dev
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
The math library must be linked. Verify the Makefile includes -lm in the linking step:
$(CC) $(CFLAGS) -o $(NAME) $(OBJS) -L$(MINILIBX_DIR) -lmlx -L$(LIBFT_DIR) -lft -lm -lX11 -lXext

Verification

After successful installation, verify everything works:
# Check the executable exists
which cub3d || echo "./cub3d"

# Test with a sample map
./cub3d maps/COME.cub
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