The build process: from source to firmware
The flow through preprocessing, compiling, assembling and linking into an executable, and how to read link errors.
Behind one press of the build button there are four stages.
| Stage | Input → output | What it does |
|---|---|---|
| Preprocess | .c → .i | Expands includes and defines |
| Compile | .i → .s | C to assembly |
| Assemble | .s → .o | Assembly to a machine-code object file |
| Link | several .o → .elf | Fixes function and variable addresses and merges everything |
Extracting the needed parts of the .elf gives the .bin or .hex that is programmed into the MCU.
Telling which stage an error came from
undeclared identifier: compile stage. A missing header or a typoundefined reference to 'foo': link stage. Declared, but the .c file with the definition is missing from the buildmultiple definition of 'x': link stage. A variable defined in a header ended up in several filesregion FLASH overflowed: link stage. The code is larger than Flash
The map file
The .map file the linker leaves behind shows which address each function and variable was placed at and how many bytes it takes. It is the first file to open when Flash or RAM runs short.