Yes, it works differently, as you can see from the compilation output
Detecting libraries used...
"C:\\Users\\Maxi\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino5/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10810 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Users\\Maxi\\Desktop\\Programming_stuff\\arduino-1.8.8\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Users\\Maxi\\Desktop\\Programming_stuff\\arduino-1.8.8\\hardware\\arduino\\avr\\variants\\standard" "C:\\Users\\Maxi\\AppData\\Local\\Temp\\arduino_build_275963\\sketch\\sketch_feb13a.ino.cpp" -o nul
Error while detecting libraries included by C:\Users\Maxi\AppData\Local\Temp\arduino_build_275963\sketch\sketch_feb13a.ino.cpp
Generating function prototypes...
"C:\\Users\\Maxi\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino5/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10810 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Users\\Maxi\\Desktop\\Programming_stuff\\arduino-1.8.8\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Users\\Maxi\\Desktop\\Programming_stuff\\arduino-1.8.8\\hardware\\arduino\\avr\\variants\\standard" "C:\\Users\\Maxi\\AppData\\Local\\Temp\\arduino_build_275963\\sketch\\sketch_feb13a.ino.cpp" -o "C:\\Users\\Maxi\\AppData\\Local\\Temp\\arduino_build_275963\\preproc\\ctags_target_for_gcc_minus_e.cpp"
Sketch is being compiled...
"C:\\Users\\Maxi\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino5/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10810 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Users\\Maxi\\Desktop\\Programming_stuff\\arduino-1.8.8\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Users\\Maxi\\Desktop\\Programming_stuff\\arduino-1.8.8\\hardware\\arduino\\avr\\variants\\standard" "C:\\Users\\Maxi\\AppData\\Local\\Temp\\arduino_build_275963\\sketch\\sketch_feb13a.ino.cpp" -o "C:\\Users\\Maxi\\AppData\\Local\\Temp\\arduino_build_275963\\sketch\\sketch_feb13a.ino.cpp.o"
it first generates function prototypes from the .ino
fiels to share them accross all other files.
So e.g. if you have these 3 files
main.ino
/* main sketch includes config */
#include "general.h"
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
general.h
#pragma once
#define SOME_DEBUG_FLAG
part_2.ino
#ifdef SOME_DEBUG_FLAG
#error "SOME_DEBUG_FLAG defined!!!"
#else
#error "SOME_DEBUG_FLAG not defined!!"
#endif
void someFunction() {
return;
}
You can see that the part_2.ino
does not include general.h
where SOME_DEBUG_FLAG
is defined. Yet, when compiled, the following “error” confirms that it was defined:
part_2:2:2: error: #error "SOME_DEBUG_FLAG defined!!!"
#error "SOME_DEBUG_FLAG defined!!!"
^~~~~
exit status 1
This is due to when main.ino
is pre-processed, the result is:
#include <Arduino.h>
#line 1 "C:\\Users\\Maxi\\Documents\\Arduino\\sketch_feb13a\\sketch_feb13a.ino"
/* main sketch includes config */
#include "general.h"
#line 4 "C:\\Users\\Maxi\\Documents\\Arduino\\sketch_feb13a\\sketch_feb13a.ino"
void setup();
#line 9 "C:\\Users\\Maxi\\Documents\\Arduino\\sketch_feb13a\\sketch_feb13a.ino"
void loop();
#line 7 "C:\\Users\\Maxi\\Documents\\Arduino\\sketch_feb13a\\part_2.ino"
void someFunction();
#line 4 "C:\\Users\\Maxi\\Documents\\Arduino\\sketch_feb13a\\sketch_feb13a.ino"
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
#line 1 "C:\\Users\\Maxi\\Documents\\Arduino\\sketch_feb13a\\part_2.ino"
#ifdef SOME_DEBUG_FLAG
#error "SOME_DEBUG_FLAG defined!!!"
#else
#error "SOME_DEBUG_FLAG not defined!!"
#endif
void someFunction() {
return;
}
As you can see, all the .ino
files hahve simply been concatinated after each other, starting at the main.ino, producing on giant .cpp
file.
That’s why when you look at the debug.ino file, it doesn’t seem to be including anything (and still work), but under the hood the Arduino IDE has concatinated every ´ino, starting at the main
espurna.ino`, which as a first act includes the configuration file, which makes the debug flags visible.
When you’re using PlatformIO it compiles the .cpp
files as their own compilation unit (which is absolutely standard). So that side-effect of the Arduino IDE is not done there. PlatformIO can still do it though, you just have to use .ino
files everywhere, too.
However, I would highly sugest to write proper C++ code in .cpp
file, not Arduino’s hacky .ino
file + preprocessing format.