I'm not entirely sure what the arduino-builder
does, but it should be similar to the traditional method.
Given the "bare minimum" sketch of:
void setup() {
}
void loop() {
}
First the IDE combines all .ino
and .pde
files together into one large one. I believe the order of concatenation is:
- Start with the "main" INO file (the one named the same as the folder it's in).
- Append to that each other
.ino
or .pde
file in alphabetical order.
Then the IDE will add the required #include <Arduino.h>
and function prototypes for any functions found - so it would end up as:
#include <Arduino.h>
void setup();
void loop();
void setup() {
}
void loop() {
}
Finally it runs normal gcc
and g++
commands on the generated file(s). You can find the generated file(s) in the build folder. Where that is depends on the operating system you are using. Turn on verbose compilation in the preferences and you can see the gcc
and g++
commands that are being executed, and as well the paths for the files involved, which lets you then see where the preprocessed files are stored.
Another important step the IDE performs, which doesn't modify the files themselves, is to look for any #include
entries that match libraries and add -I <path>
to the compilation commands for those libraries. It also then finds any source files associated with those libraries and compiles them. It also compiles all the core source files, which is where the main()
functions is (see @jantje's answer for details on how the main()
function is formed).
Once the IDE has finished with its parsing and processing it's all standard gcc
and g++
.