Looking for a more robust way of including libraries into a project

I am working on a rather large project (ESP32 / Arduino framework).
I now have 12+ modules such as ‘touchscreen’, ‘network’, ‘filesystem’, etc. and each of these modules are in separate folder / files under the folder ‘lib’. Of course these modules interact a lot, so many modules include the header files of other modules. Finally these modules use many built-in libraries such as WiFi.h etc. so these are also included.

As my project gets bigger, I am running into problems with the well known “fatal error: WiFi.h: No such file or directory” (see eg. Why is WiFi.h not found by compiler)

I already have lib_deps = WiFi
and I have lib_ldf_mode = chain+
but still I am running into problems when the compiler doesn’t find header files, which are obviously there, because you can simply ctrl+click on them and they open…

QUESTION : Instead of relying on the magic of the LDF, is there not a more robust, manual way of defining all libraries…

  • own in ‘lib’ folder (12+ subfolders)
  • on github (5 libraries)
  • built-in, eg. ESP32-Arduino framework
    …so that these include errors are a thing of the past.
    I think it would also build faster that way because the LDF (chain+) takes quite some time now.

Are there any examples / docs / blogposts on how to do this ? I think it’s a must have for professional. large project developments.

The LDF always decides which libraries make it into the final build, there is no bypassing that, just a massaging into the LDF doing the right thing can be done.

Can you upload that project or a minimal version thereof which shows that problem? We’d surely like to take look into why that is occuring in this scenario.

1 Like

Ok, thanks @maxgerhardt
I will prepare an example with a ‘before’ (builds) and ‘after’ (build fails) as soon as I run into the problem again.
Should be one of the next days.

@maxgerhardt : I have sent you a private message with an example (before / after) and short explanation of what I am doing…



Have you found a way for more robust build?

I spend to much time trying to understand why part of my code base suddenly not can be built any more.

I have not touched it, just spent time on other parts of the application.

sorry for my late reply, I was on a sailing trip with no internet.

People from Platformio have investigated my example, and I’ve come to the following conclusion : my problem mainly occurs because of so-called circular include statements:

  • A.h includes B.h
  • B.h includes A.h
    This should be OK if there are header guards, or #pragma once (which I am using nowadays).
    However, I have the feeling that Platformio Library Finder (LDF) does not like this circular includes and may give up at some stage, not including important other stuff…

So the solution is not so difficult : extract everything which is common for A.h and B.h into a separate C.h so that

  • A.h includes C.h
  • B.h includes C.h

Hope this helps you forward.

Kind regards, Pascal