Have you tried Arduino and already built your first sketch with a single click? Or maybe you’re just starting to explore embedded devices and see Arduino as the easiest way to begin. Either way, understanding the internals of the build process is a great way to boost your skills!
In this post, I’ll summarize the Arduino build process.
For the full article, check out my guide on my blog, which contains more detailed explanation.
The Arduino sketch build process follows the typical embedded/C++ application build steps, with additional Arduino-specifics.
Since the Arduino IDE 2.0, the IDE uses Arduino CLI underneath for the build process. Steps will be the same when building directly via CLI.
General C/C++ application build process
The general build process is shown below. Let’s take a closer look at how the Arduino environment adapts it.
1. Preprocessing – preparing the sketch
This stage includes most of the Arduino-specific steps, designed to make development as easy as possible for beginners.
-
Combining files: All
.ino
files in the sketch folder are merged into a single.cpp
file. -
Detecting used libraries: Libraries included via
#include
are identified and stored for compilation and linking. This saves you the need to manually configure used libraries, like in other embedded development environments. -
Adding headers: If
#include <Arduino.h>
is missing, the Arduino environment adds it automatically. - Function prototypes: Missing prototypes are generated automatically. Thanks to this, you don’t need to type them during development, and can add functions in any order.
-
Line directives:
#line
directives are added to maintain accurate line numbers in error messages. This is necessary because your code is written in.ino
files, which are automatically converted into.cpp
files during preprocessing, and the original line numbers are not matching the line numbers from post-processedino.cpp
file. - Expanding code: Expands macros and processes includes.
2. Compilation
Compilation is changing the human-readable code into assembly code, which later gets transformed into machine code. Modern compilers perform both compilation and assembly in one step.
- Sketch compilation: The sketch is compiled using the board-specific compiler.
- Library compilation: All libraries detected in previous step are compiled.
- Core compilation: The Arduino core for the selected board is compiled.
3. Linking
All compiled object files, used libraries and the Arduino core libraries are linked into a single ELF file (Executable and Linkable Format).
4. Generating binary files
The ELF file is converted into HEX and BIN. The sketch is ready to upload to Arduino board.
Tip: To see detailed compilation steps, enable “Show verbose output” in Arduino IDE. This lets you track every step of the build process.