You can find out what the IDE exactly does by enabling verbose output during compilation in file -> preferences.
You will see lots of information; the relevant part to search for is your sketch name, e.g. Sweep.ino. One of the lines that contains this information is e.g. C:\Users\yourUserName\AppData\Local\Temp\arduino_build_629284\sketch\Sweep.ino.cpp.o
. Navigate to the indicated (sketch) directory and you will find the file yourSketch.ino.cpp which is the file that is created by the Arduino builder and is the actual source file that goes through the 'compile' process.
One thing you need to know is that the compiler needs to be aware of any variable or function before it is used or called in the code. The Arduino builder sometimes drops a stitch and e.g. does not place a function prototype in the correct place (or at all) in the final CPP.
This simple sketch demonstrates the failure.
main sketch (MultipleIno.ino)
void setup()
{
calc(3);
}
void loop()
{
}
tabOne.ino
int calc(int y)
{
return x+y;
}
tabTwo.ino
int x = 0;
The error is
C:\Users\sterretje\Documents\Arduino\DemoCode\MultipleIno\tabOne.ino: In function 'int calc(int)':
tabOne:3: error: 'x' was not declared in this scope
return x+y;
The resulting MultipleIno.ino.cpp
#include <Arduino.h>
#line 1 "C:\\Users\\sterretje\\Documents\\Arduino\\DemoCode\\MultipleIno\\MultipleIno.ino"
#line 1 "C:\\Users\\sterretje\\Documents\\Arduino\\DemoCode\\MultipleIno\\MultipleIno.ino"
#line 1 "C:\\Users\\sterretje\\Documents\\Arduino\\DemoCode\\MultipleIno\\MultipleIno.ino"
void setup();
#line 7 "C:\\Users\\sterretje\\Documents\\Arduino\\DemoCode\\MultipleIno\\MultipleIno.ino"
void loop();
#line 2 "C:\\Users\\sterretje\\Documents\\Arduino\\DemoCode\\MultipleIno\\tabOne.ino"
int calc(int y);
#line 1 "C:\\Users\\sterretje\\Documents\\Arduino\\DemoCode\\MultipleIno\\MultipleIno.ino"
void setup()
{
calc(3);
}
void loop()
{
}
#line 1 "C:\\Users\\sterretje\\Documents\\Arduino\\DemoCode\\MultipleIno\\tabOne.ino"
int calc(int y)
{
return x+y;
}
#line 1 "C:\\Users\\sterretje\\Documents\\Arduino\\DemoCode\\MultipleIno\\tabTwo.ino"
int x = 0;
You can see where the variable x is declared (after the calc function where it is used) and hence it's unknown in the calc function. Swapping the content of tabOne.ino and tabTwo.ino solves the problem in this case.
The most interesting lines are probably
#line 2 "C:\\Users\\sterretje\\Documents\\Arduino\\DemoCode\\MultipleIno\\tabOne.ino"
int calc(int y);
int calc(int y);
is a so-called function prototype that tells the compiler what the function 'looks like'; if you e.g. omit the argument in the function call, the compiler can (and will) tell you that something is wrong. Sometimes the Arduino builder does not include that prototype.