I'm trying to look through the Arduino core to find where "mySketch.ino" is included or implemented. In 'Arduino.h', the prototypes void setup(void)
and void loop(void)
are defined, in 'main.cpp', setup(void)
and loop(void)
are called, but I'm not sure where 'main.cpp' or any other related files makes a reference to the sketch.
Where does this occur?
-
2The files don't reference the sketch. They don't need to. That's not how C compiling works. Look up "Linking (Compiling)" in Google to understand more.Majenko– Majenko2019年02月20日 01:11:30 +00:00Commented Feb 20, 2019 at 1:11
-
Here is the "main()" source file for the Arduino core. github.com/arduino/ArduinoCore-avr/blob/master/cores/arduino/…Mikael Patel– Mikael Patel2019年02月20日 20:38:20 +00:00Commented Feb 20, 2019 at 20:38
1 Answer 1
Compilation doesn't start with the Arduino.h or the core files; rather, it starts with your own sketch, "whatever.ino". Your .ino file includes Arduino.h into the compilation which makes references to core modules. That compilation leaves many references to to be satisfied, and itself satisfies several - setup() and loop(), for two. At link time, the linker is told to read not only your compiled module(s), but also the compiled core files, from which it can extracts the modules required to satisfy references made by your compiled code. Then it combines your module, and those modules required by it, into the load file that avrdude uploads to the Arduino.
-
1Just want to add, that the Arduino IDE also concatenates all the .ino files in the same sketch together; .cpp, files are compiled automatically as well, but are not modified like the .ino files.esoterik– esoterik2019年02月20日 04:08:45 +00:00Commented Feb 20, 2019 at 4:08