undefined reference error when using Platform IO with the Arduino framework
One of many possible solutions for the pesky ‘undefined reference’ error
Summary
The Arduino framework for Platform IO expects library files to be named with the suffix .cpp, not .c.
The problem
I wrote some carefully crafted library files for a project which contained lovingly sculpted functions and structures. However, when I built the project I got the dreaded:
undefined reference
error. I checked that I declared the .h header file for my library files everywhere and anywhere. I checked that I had the correct spelling of the new functions. I said some naughty words.
The solution
I needed to change the suffix of my library file names to be .cpp, not .c. That simple.
More waffle
There are many reasons to get the undefined reference error. This is just one of them. I hope that this post helps somebody, somewhere to avoid the few hours I wasted before having the ‘head slapping’ realisation of what the error was.