Compiler errors in PIO but not in Arduino IDE

Hello together. I recently found out about platformio and switched to it because I copy all my code and header files into the arduino IDE which is a mess.
But sadly, with exactly the same code I get a ton of compiler errors in platformio but not a single one in the arduino IDE.

<artificial>:(.text.startup+0x2ba): undefined reference to `LEFT_SERVO'
<artificial>:(.text.startup+0x2bc): undefined reference to `LEFT_SERVO'
<artificial>:(.text.startup+0x2c6): undefined reference to `RIGHT_SERVO'
<artificial>:(.text.startup+0x2c8): undefined reference to `RIGHT_SERVO'
<artificial>:(.text.startup+0x2d2): undefined reference to `CENTER_SERVO'
<artificial>:(.text.startup+0x2d4): undefined reference to `CENTER_SERVO'
<artificial>:(.text.startup+0x2e2): undefined reference to `startUpRoutine()'

LEFT_SERVO, RIGHT_SERVO and CENTER_SERVO are defined in the servo_drive files:
.h file:

extern Servo LEFT_SERVO;
extern Servo RIGHT_SERVO;
extern Servo CENTER_SERVO;

.cpp file:


startUpRoutine() is declared like this in my .h file:

void startUpRoutine();

and in my cpp file there is the whole function.

Where is the error? Why does it work in Arduino IDE?

For some reason, putting all my include files in the src/ folder fixed the issue… If someone knows why, i’d be glad to know.

If you turn on verbose compiling then you will see that for your main program, src and include are searched for header files – the options will be -I src -I include. If you have any other locations for your own include files, then you will need to add something like:

build_flags =

The indentation is 4 spaces or a tab character, it’s for Python, so the indentation is required in this format.

If you are building a library of your own, or have downloaded as sources, then:

  • Each separate library goes has a separate sub-directory in lib.
  • All the source and header files for the individual libraries live in the same folder, there is no inclusion of the include or src directories when the libraries are being compiled.