Confusion with the library dependency declarations in platformio.ini targeting Arduino framework

Hello.

I’m quite puzzled with managing library dependencies for an application targeting Arduino framework. It seems that platform.io arbitrarily demands certain framework libraries to be declared in lib_deps, such libraries include “SPI”, “Wire”, and “SoftwareSerial”, while other framework libraries such as “HardwareSerial” need not to be explicitly declared.

What’s the rule there? Is there a better way than doing trial-and-error to find out whether a platform library needs to be explicitly listed in lib_deps?

Thanks.

HardwareSerial.h is in the Arduino core, which is always compiled. There is no need to declare that. SPI, Wire and SoftwareSerial are libraries found in the Arduino core’s libraries/ folder. You do not need to declare built-in framework libraries if you just include them in your program, the library dependency finder usually finds them.

Note that the LDF has a quirk in which where you include a library via lib_deps, say, the Adafruit BusIO library, which itself depends on SPI and Wire, will not have its dependencies discovered correctly if there is no inclusion of that library’s header in the main program (#include <Adafruit_BusIO.h> in this case). Once you do that, there is no need to ad SPI and Wire to the lib_deps.

Thanks Maximilian, that makes a ton of sense.