> ## Content Index
> Fetch the complete content index at: https://evil-penguin.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# MLX Starter Pack
- URL: https://evil-penguin.com/mlx-starter-pack/
- Published: 2022-04-28T20:04:20.000Z
- Updated: 2026-11-16T23:12:54.000Z
- Description: Scaffold for any MLX project
- Author: evilpenguin
- Tags: 42, C, Linux, MLX

## minilibx made easy for you!

In this tutorial, I will show you the best way to start a project that uses minilibx.  
First and more importantly I encourage you to read the 5 manuals ***RTFM.***  
  
> I personally don't think that you should understand EVERYTHING that is in the manual, you only have to read them and know the information inside the manual.  
> This is extremely helpful because when you have a question/problem you know where to find the answer, and at that point, you will need to understand that specific part of the manual.

1. mlx
2. mlx\_loop
3. mlx\_new\_image
4. mlx\_new\_window
5. mlx\_pixel\_put

## Covering The Basics

> "You must use the MiniLibX. Either the version available on the school machines or installing it using its sources." (from the subjects)

This means that your project should compile and work with the school's machines and also with the sources that they give you on the project page.  
(The sources are provided on the project page as shown below). 

![](https://evil-penguin.com/content/images/2026/11/intra_minilibx.png)

Probably you want to be able to run your code on your personal computer, to do so follow these steps.  
Go to your project page at intra.42.fr and download the adequate source for your OS...  
If you rather feel "powerful" you can execute something like this:  
  
cd \~/  
mkdir tutorial\_minilibx  
cd tutorial\_minilibx  
curl -O https://projects.intra.42.fr/uploads/document/document/8330/minilibx\_opengl.tgz  
tar -xvf minilibx\_opengl.tgz   
ls minilibx\_opengl\_20191021/

![](https://evil-penguin.com/content/images/2026/11/compileMLX.gif)

## Headers and Libraries

# **Headers**

All computers should have a "usr/local/include" folder (or equivalent) where the user can create header files that will be included automatically when compiling your code.  
At this point, you should have noticed that when you include standard libraries you use **<lib.h>**,and when you want to include your own headers you use **"mylib.h"**.  
I think it's logical to add minilibx headers to this folder so that your project can compile using **#include <mlx.h>.**  
[https://gcc.gnu.org/onlinedocs/cpp/Include-Syntax.html](https://gcc.gnu.org/onlinedocs/cpp/Include-Syntax.html?ref=evil-penguin.com) \- [https://gcc.gnu.org/onlinedocs/cpp/Environment-Variables.html](https://gcc.gnu.org/onlinedocs/cpp/Environment-Variables.html?ref=evil-penguin.com) (You can read more about how Include works here)If you are curious you can find out all the paths where gcc looks for your headers, for **".h"** & **<.h>** ...  
Run this to find out :echo | cpp -Wp,-v  
If you are even more curious to understand what that command was, you can find out with: *gcc -help* **or** *man cc*

- cpp (or *gcc -E*) ([https://gcc.gnu.org/onlinedocs/cpp/Invocation.html](https://gcc.gnu.org/onlinedocs/cpp/Invocation.html?ref=evil-penguin.com))
- \-E Only run the preprocessor.
- \-Wp,<arg> Pass the comma separated arguments in <arg> to the preprocessor.
- \-v Show commands to run and use verbose output.

After you founded out where gcc looks for your headers you can copy the 5 headers that you downloaded from minilibx source:

1. mlx.h
2. mlx\_int.h
3. mlx\_new\_window.h
4. mlx\_opengl.h
5. mlx\_png.h

Now, you will be able to include the headers with **<mlx.h>** and you won't have to worry about linking them, and yes the school machines have these headers installed.

# **MLX library**

As you might remember from libft, libraries help you collect/arrange a set of functions, definitions, structures; etc all in one place and you only need to compile them once.  
You will need to compile the mlx source files that you downloaded. If you were meticulous you would have noticed that the sources came with a Makefile.  
Compile the minilibx source Makefile with "***make***".  
After 100000 warnings you should get your precious **libmlx.a** (i.e. your OS minilibx library!)  
  
Sometimes there is a test folder in the minilibx project, don't hesitate to run the executable and try to understand what's happening!

![](https://evil-penguin.com/content/images/2026/11/gcc_config.png)

![](https://evil-penguin.com/content/images/2026/11/combine_images-removebg-preview-1.png)

# **Libraries**

Just like the Headers, you can also add local libraries to your computer. You can also use this tutorial to add your **libft.a** to your computer :D  
gcc will also look for your local libraries, usually under "/usr/local/lib/".  
You can just drop libmlx.a and libft.a (if you want) there, and you won't have to worry about linking the libraries.  
If you don't want to do this or you don't have permission on the computer to place files there, you can link the libraries, with the "-L PATH\_TO\_LIBRARY -l lib\_name".  
Example (assuming libmlx.a is on the path used bellow):***\-L tutorial\_minilibx/minilibx\_opengl\_20191021 -l mlx***Now you should be able to include your minilibx headers and library to start your project.  
I attached a picture below of a simple main "including" mlx and compiling. You should be able to compile as well...  
\[Rememeber to copy your libft project if the subject allows it\]

![](https://evil-penguin.com/content/images/2026/11/compileHeaders.png)

## Makefile

You will need a Makefile to compile your project, this part is very intimate, and every person has their own way to organize their code, therefore compile their code as well.  
As a "rule", the Makefile needs to be at the root of your project because it only makes sense. It should have the rules "NAME, all, clean, fclean, re" according to the subjects.  
I like to have the Makefile on the root and create folders on the root according to what they are used for. I would create the following folders: "include" "src(sources)" "assets" "maps" "libft" and so forth...  
  
**Variables**  
  
NAME = project\_name  
INC = /usr/local/include# could be /usr/include depending on your OS  
INCFT = ./libft/include# header from libft  
LIBFT = ./libft# path to libft library  
LIBMLX = /usr/local/lib# could be /usr/lib, depends on where you decided to put your mlx library  
UNAME := $(shell uname)# get the OS name, this will help define behaviors for certain OS's  
CFLAGS = -Wall -Werror -Wextra -O3 -g -I$(INC) -I${INCFT} -Iinclude# C Flags (gcc) & linking. "-Iinclude" if you created the folder "include" to put your project headers"  
LFLAGS = -L$(LIBMLX) -lmlx -L${LIBFT} -lft# if you decided to install libmlx.a locally you don't need "-L$(LIBMLX) -lmlx" the school also has it locally as well...  
SRC = $(wildcard src/\*.c)# list your source files  
OBJ = $(SRC:%.c=%.o)# convert source files to binary list  
**Enable compilation for Linux, FreeBSD, and darwin.**  
  
ifeq ($(UNAME), Darwin) # iMac / iOS  
 CC = gcc  
 LFLAGS += -framework OpenGL -framework AppKit  
else ifeq ($(UNAME), FreeBSD) # FreeBSD  
 CC = clang  
else #Linux and others...  
 CC = gcc  
 LFLAGS += -lbsd -lXext -lX11 -lm  
endif  
**Compilation.**  
  
all: $(NAME)  
  
$(NAME): runlibft $(OBJ)  
 $(CC) -o $(NAME) $(OBJ) $(LFLAGS)  
  
runlibft:  
 make -C libft --no-print-directory  
  
clean:  
 rm -f $(OBJ)  
fclean: clean  
 rm -f $(NAME)  
  
re: fclean all  
  
show:  
 @printf "UNAME : $(UNAME)\\n"  
 @printf "NAME : $(NAME)\\n"  
 @printf "CC : $(CC)\\n"  
 @printf "CFLAGS : $(CFLAGS)\\n"  
 @printf "LFLAGS : $(LFLAGS)\\n"  
 @printf "SRC : $(SRC)\\n"  
 @printf "OBJ : $(OBJ)\\n"  
  
**Makefile**

```makefile
NAME    = tutorial#
INC     = /usr/local/include#						# could be /usr/include depending on your OS
INCFT   = ./libft/include#						# header from libft
LIBFT   = ./libft#							# path to libft library
LIBMLX  = /usr/local/lib#						# could be /usr/lib or minilibx_opengl_20191021/, depends on where you decided to put your mlx library 
UNAME   := $(shell uname)#						# UNAME will get the OS name, this will help define behaviors for certain OS's
CFLAGS  = -Wall -Werror -Wextra -O3 -g -I$(INC) -I${INCFT} -Iinclude#	# C Flags (gcc) & linking. "-Iinclude" if you created the folder "include" to put your project headers"
LFLAGS  = -L$(LIBMLX) -lmlx# -L${LIBFT} -lft#				# if you decided to install libmlx.a locally you don't need "-L$(LIBMLX) -lmlx" the school also has it locally as well...
SRC     = $(wildcard src/*.c)#						# list your source files
OBJ     = $(SRC:%.c=%.o)#						# convert source files to binary list

ifeq ($(UNAME), Darwin) # iMac / iOS
	CC = gcc
	LFLAGS += -framework OpenGL -framework AppKit
else ifeq ($(UNAME), FreeBSD) # FreeBSD
	CC = clang
else #Linux and others...
	CC = gcc
	LFLAGS += -lbsd -lXext -lX11 -lm
endif

all: $(NAME)

$(NAME): runlibft $(OBJ) show
	$(CC) $(OBJ) $(LFLAGS) -o $(NAME)

runlibft:
	@#RUN LIBFT IF YOU NEED IT : #make -C libft --no-print-directory

clean:
	rm -f $(OBJ)
fclean: clean
	rm -f $(NAME)

re: fclean all

show:
	@printf "UNAME		: $(UNAME)\n"
	@printf "NAME  		: $(NAME)\n"
	@printf "CC		: $(CC)\n"
	@printf "CFLAGS		: $(CFLAGS)\n"
	@printf "LFLAGS		: $(LFLAGS)\n"
	@printf "SRC		: $(SRC)\n"
	@printf "OBJ		: $(OBJ)\n"

PHONY: show fclean clean all

```

## Tutorial...

If many people like this post I will create a tutorial for a minilibx super small project to get started:  
Also you can just download the tutorial or check it out here:  
(If you download the tutorial\_minilib.zip file you will need to replace the libft with your libft or remove the runlibft rule from the Makefile)  
[https://github.com/pulgamecanica/42Course/tree/main/42Documentation/tutorial\_minilibx](https://github.com/pulgamecanica/42Course/tree/main/42Documentation/tutorial%5Fminilibx?ref=evil-penguin.com)  
  
I did create the tutorial... :)  
[Tutorial](https://pulgamecanica.herokuapp.com/posts/minilibx-tutorial?ref=evil-penguin.com)

[⬇ Tutorials.zip](https://evil-penguin.com/content/files/2026/11/Tutorials.zip)

![](https://evil-penguin.com/content/images/2026/11/Screenshot_2022-12-28_at_23.19.43.png)