I have an Arduino project with multiple .h and .cpp files in the “src” folder, alongside my main project.cpp file. It seems like all the .h files are being linked, but none of the .cpp files. All the calls to functions defined in those files are resulting in “undefined reference” at build-time, even though function signatures are there in the .h files. This used to work perfectly in Arduino IDE, but in PlatformIO it’s broken. What am I doing wrong?
Full project is here: GitHub - xoxota99/stewy: Arduino project for a 6DOF, PID-controlled Stewart platform, running on Arduino. Inspired by https://www.youtube.com/watch?v=j4OmVLc_oDw . , and I’ll try to post a minimal example when I get home.
Please move all files to
src root from nested folder.
Thanks Ivan. Tried that, but nothing changed. Still getting “undefined reference” for any functions defined in another .cpp file. Using a #pragma message, I can see that my .h files are being processed, but not my .cpp files.
EDIT: Looks like the .cpp files are being compiled, but not linked? (Tested this by introducing a syntax error in one of the secondary .cpp files). Don’t know why the preprocessor wouldn’t hit the #pragma message if that’s the case, though.
Looks like renaming all my .cpp files to .ino just makes everything work. I have no idea why, but at this point I’ve been bashing my head against this for a day or two, so I’ll take whatever unsatisfactory resolution I can. If anyone has any bright ideas how I can switch these back to .cpp, I’m all ears.