Prerequisites
Before building Cub3D, ensure you have the following dependencies installed on your Linux system:C Compiler
GCC or compatible C compiler (specified as
cc in Makefile)X11 Libraries
X11 and Xext libraries for window management
Math Library
Standard math library (
libm)Make
GNU Make for build automation
Required Libraries
Cub3D depends on two main libraries that are included in the source:- libft - Custom C utility library (located in
libft/) - MiniLibX - Minimal X11 graphics library (located in
minilibx-linux/)
Build Process
Follow these steps to build Cub3D from source:Clone or download the repository
Ensure you have the complete Cub3D source code with all subdirectories:
Build the project
Run the default Make target to compile everything:This command will:
- Build the MiniLibX library
- Build the libft library
- Compile all Cub3D source files
- Link everything into the
cub3dexecutable
Compilation Details
Compiler Flags
Cub3D is compiled with the following flags as defined in the Makefile:The
-Wall -Wextra -Werror flags ensure strict compliance with coding standards by treating all warnings as errors.- -Wall -Wextra: Enable comprehensive warning messages
- -Werror: Treat warnings as compilation errors
- -O3: Enable maximum optimization for performance
- -g -g3: Include detailed debugging symbols
Linking
The final linking step connects all object files and libraries:-lmlx: MiniLibX graphics library-lft: Custom libft utility library-lm: Math library (for trigonometric functions)-lX11 -lXext: X Window System libraries
Source Files
The following source files are compiled:Makefile Targets
The Makefile provides several targets for different build operations:make or make all
Builds the complete project including all dependencies.
This is the default target - running
make without arguments executes make all.make clean
Removes object files (.o) from the Cub3D directory and cleans the libft directory:
- Removes all
*.ofiles from the current directory - Runs
make cleanin the libft subdirectory - Leaves executables and libraries intact
make fclean
Performs a full clean, removing all build artifacts:
- Executes
make cleanfirst - Removes the
cub3dexecutable - Runs
make fcleanin libft (removeslibft.a)
make re
Rebuild everything from scratch:
- Executes
make fcleanto remove all build artifacts - Executes
make allto rebuild from scratch
Use
make re when you want to ensure a completely clean build, especially after making significant changes to source files or headers.Troubleshooting
MiniLibX Build Failures
If the MiniLibX library fails to build, ensure you have the X11 development packages installed:Missing Math Functions
If you encounter “undefined reference” errors for math functions likecos, sin, or sqrt, verify that the math library is being linked with the -lm flag.
Compilation Warnings
Due to the-Werror flag, any compiler warning will halt the build. Review the error message carefully and fix the indicated issue in the source code.
Build Output Example
A successful build should produce output similar to:Next Steps
After successfully building Cub3D, you’re ready to run it:Running Cub3D
Learn how to execute Cub3D and load map files