How to Create a Simple Makefile - Introduction to Makefiles

Paul Programming · 885K views · 2015 · 9:24

Open on YouTube

C, C++, Rust, Go & systems languagesTesting, debugging & developer toolsEducation & learningtutorial

Why Stack Overflow recommends it

Stack Overflow users link it as a quick, simple introduction to writing a first makefile, and askers cite it as the tutorial they followed.

Recommended by 1 people across 1 different months, 2019 to 2023.

What it is

A short beginner tutorial by Paul Programming that walks through writing a simple makefile for a small C++ project. It covers targets, dependencies and compile commands in a basic example.

What people said

Recommends Luc Hermitte · 2020-04 · Stack Overflow · on “How to compile a cpp file directly from vim editor in Windows?”

The screenshot of the first link I see in google with "write Makefile" seems good and simple enough to me: [this video]

Cites csguy · 2019-08 · Stack Overflow · on “Proper makefile dependency list (C++)”

A lot of the examples I see regarding make files are somewhat inconsistent in regards to what files are considered dependencies of main.o and I was wondering what is the safest and most efficient way of going about creating a makefile. An example from [LINK] : hello: main.o factorial.o hello.o $(CC) main.o factorial.o hello.o -o hello main.o: main.cpp functions.h $(CC) -c main.cpp factorial.o: factorial.cpp functions.h $(CC) -c factorial.cpp hello.o: hello.cpp functions.h $(CC) -c hello.cpp As you can see, the header file functions.h is a dependency of main.o . An example from my textbook: myprog.exe : main.o threeintsfcts.o g++ main.o threeintsfcts.o -o myprog.exe main.o : main.cpp threeint

Cites Yohio · 2023-07 · Stack Overflow · on “Can't get makefile to create executable”

I'm trying to make a program that needs an executable, and i've followed this tutorial [this video] , but i can't seem to get an executable. I get all the o-files so i don't really get what's wrong CC = gcc CFLAGS = -g -std=gnu11 -Wall mmake: mmake.o parser.o $(CC) $(CFLAGS) -o mmake parser.o mmake.o parser.o: parser.c parser.h $(CC) $(CFLAGS) -c parser.c mmake.o: mmake.c $(CC) $(CFLAGS) -c mmake.c I've tried looking at other makefiles but they seem vastly more complex than mine so they don't help so much My output below gcc -g -std=gnu11 -Wall -c mmake.c gcc -g -std=gnu11 -Wall -c parser.c gcc -g -std=gnu11 -Wall -o mmake parser.o mmake.o /usr/bin/ld: mmake.o: in function `parse_makefile': /home