Library framework dependencies not found during compilation

Hi all!

I’m developing a PlatformIO library that depends on some built-in libraries of the Arduino framework (e.g. WiFi.h, ArduinoOTA.h,…).

While compiling the library I got the following error from the compiler:

fatal error: WiFi.h: No such file or directory

I’m sure that the library is not missing as I can find it inside the framework files.

After some investigation I found out that it was a problem related to the LDF that wasn’t able to find the dependencies of the library and include them during compilation.

The structure of the library is pretty simple and follows the Creating Library guide:

├── include/
│   └── library.h
├── src/
│   └── library.cpp
└── library.json

All the dependencies are included in library.h, which is included in library.cpp.

How can I solve this issue?

Thanks for the help!

Is library.h included in the projects main source? This is a quirk of the LDF.

Also, in cases where the #include <WiFi.h> is behind an #ifdef check, this will not work the default lib_ldf_mode settings. You can also set this in the library.json.

Yes it is included in library.cpp.

Actually yes, all the includes are inside library.h, which has the usual #ifndef ... #define ... at the beginning. However, either using the chain+ mode or moving the includes in the library.cpp file doesn’t change the result, I still get the compilation error.

The general include guards okay, but stuff like

#include <WiFi.h>

is where the default LDF settings break down.

Ok finally I solved by using the deep mode of the LDF, setting it in the library.json file:

"build": {
    "libLDFMode": "deep"

But now I’m wondering if this is the proper way to handle framework dependencies in libraries, since it’s written also in the documentation that it’s not generally recommended to use the deep mode.

No, I mean the projects e.g. src\main.cpp. The LDF only recognizes nested dependencies of libraries that are also included in the main project files.

Ah ok, actually no it wasn’t included in the main.cpp, I just created a new PlatformIO project, added my library and then compiled.

Including it solves everything, without the need to use the deep mode of the LDF.

Is it normal that you have to include the library to avoid compilation errors?

It is normal by PlatformIO standards, but definitely an unintuitive quirk.

Clear, thank you very much for your help.
Have a nice day!