How to make subfolders under src included recursively

Any way to make the src directory work recursively like the lib directory?

I’m trying to figure out the cleanest way to organize a project like this:


  • project/platformio.ini
  • project/src/main.cpp
  • project/src/sub/classfile.cpp
  • project/src/sub/classfile.h

and be able to

#include "classfile.h"

from main.cpp.

I can do this if I put the classes under the lib directory, but want to have those be just shared libraries.

PlatformIO adds -Isrc by default to Preprocessor. If you need additional includes, please take a look at build_flags option.

However, I don’t recommend to add extra includes. Please use

#include "sub/classfile.h"
1 Like

Good advice, thanks Ivan.

1 Like

Ivan’s suggestion is the “right way” to do this. Always favor explicitly stating what folder the include files live in.

Otherwise, .h files in various folders can easily collide - creating a lot of time consuming mysterious compiler errors.

1 Like