Inside a C Build

Two tiny files, main.c and square.c, followed through five machines until the screen says 25. Every byte, address and message on the board came from a real gcc 13.3 run on Linux x86-64.

Step through with Next, or press Play. With sound on, a voice reads each step. When a red box asks you to predict, pick an answer before you move on. Click a machine on the board to jump to it.

look:
30 more themes from the video kit
Stage board

Watch it as a film

The same board, narrated end to end, about eight and a half minutes. The film matches the look you picked above when one exists; otherwise pick one here. Captions are on the CC button.

film:

Companion film: The Life of main.c

The same journey told a different way: a hand-drawn conveyor belt, a different little program (main.c with mathx.h and an add function), and a quicker pass through the flags. About five minutes. Watch it before or after the board.

Film by Kai Mori Video Pipeline.

Who threw this error?

Name the machine first. The fix depends on it.

cpp, copyfatal error: square.h: No such file or directoryfix the path, or add -I dir
cc1, compilesyn.c:2:2: error: expected ',' or ';' before 'return'starts with file:line:col, so it's your code at that spot
as, assemble(rare when you only write C)you'll almost never see this one
ld, linkundefined reference to `square'
multiple definition of `square'
missing .o or -l, wrong library order, or a definition in a header
ld.so, load + runerror while loading shared libraries: libsquare.so
Segmentation fault
.so not found, or a bug in your logic: use -g and sanitizers

Flags in one place

Want toFlagReal result here
Stop after copy, compile or assemble-E -S -cmain.i (825 lines), main.s, main.o (1,576 B)
Keep every middle file-save-tempsleft main.i, main.s, main.o
Name the output-o appwithout it: a.out
See the real commands-v -###cc1, as, collect2 (calls ld)
Headers, macros, libraries-I -D N=7 -L. -lsqlibraries go after the files that use them
Warnings-Wall -Wextra -Wshadow -Wconversion103, 156, 172 warnings on, by level
Warnings as errors-Werror -Werror=formatexit 1, no binary written
Language version-std=c17 -std=c++17defaults: gnu17 and gnu++17
Speed or debugging-O0 -Og -O2 -O3 -Os -g-g: 16,024 to 17,688 B
Catch memory and UB bugs-fsanitize=address,undefinedstack-buffer-overflow at ub.c:6
Library type-static -shared -fPIC785,392 B static

Your two g++ lines

Practice: slow, loud, catches the off-by-one.

g++ -std=c++17 -Wall -Wextra -Wshadow -Wconversion -g -fsanitize=address,undefined -D_GLIBCXX_DEBUG sol.cpp -o sol

What a judge usually runs.

g++ -std=c++17 -O2 sol.cpp -o sol

Your turn

main.c and square.c disagree about what square is:

// main.c                      // square.c
int square(int);               double square(double x) { return x * x; }

You build with gcc -Wall -Wextra main.c square.c -o app. Who catches the mismatch: the compiler, the linker, or nobody? Answer in the thread before you test it.