PlatformIO Community

Creating a platformio library with optional dependencies

I have a library registered as htcw_gfx. The trouble is that it will not use SPIFFS or SD (FS.h on ESP32, or SD.h on other platforms) because they aren’t listed as dependencies.

They can’t be listed as hard dependencies because they’re not always available. I allow you to turn off those dependencies based on platform, but I need those dependencies to be available if they’re present for the platform.

Such that on an ESP32 i have access to SPIFFS and SD (via FS.h)
And such that on most other Arduino platforms I have access to SD via SD.h)

What I need I think, is a way to list dependencies and the project will still build if they’re not present.

Failing that, any way to get what I need would be helpful.

Edit: I just realized this may not be my problem at all.

Here’s what I’m getting trying to include FS.h using node32s (ESP32) and arduino: (FS.h should be available)


  • Looking for FS.h dependency? Check our library registry!
  • CLI > platformio lib search “header:FS.h”
  • Web > PlatformIO Registry

compilation terminated.
*** [.pio\build\node32s\libd7c\htcw_gfx\gfx_font.cpp.o] Error 1
In file included from .pio\libdeps\node32s\htcw_gfx\src\io_stream.cpp:2:0:
.pio\libdeps\node32s\htcw_gfx\include/io_stream.hpp:18:24: fatal error: FS.h: No such file or directory


  • Looking for FS.h dependency? Check our library registry!
  • CLI > platformio lib search “header:FS.h”
  • Web > PlatformIO Registry

compilation terminated.
*** [.pio\build\node32s\libd7c\htcw_gfx\io_stream.cpp.o] Error 1

If all your dependencies are libraries in their respective Arduino core, and you do stuff like

#ifdef ARDUINO_ARCH_ESP32
#include <FS.h>
#endif
// ...

to inlucde it, it should suffice to up the library dependency finder’s search mode to e.g. chain+ via library.json — PlatformIO latest documentation.

If you had external library dependencies, you should still declare them as normal for all platforms / architecture, because PlatformIO will filter them out in the compatibliity check phase, which can also be controlled here.

I’m basically already doing that. Or rather, similar to that. The problem is it’s not finding the file even on an ESP32 build!

Is it necessary to include SPIFFS or SD or something to make that work? I don’t want to have to. I just want FS.h. I need the interface for File and that’s it. At any rate I didn’t think those were external dependencies to begin with. I thought they were core components.

I’ll take a look at the links you sent me but so far I’m still scratching my head over this. Thanks for your help.

Edit: adding
lib_ldf_mode = deep
to platformio.ini solved it!

Thanks again for your help.

1 Like