ESP32: Can't find Preferences.h

I’m trying to build a project on the ESP32 (specifically the SF Thing Plus, which uses the Feather ESP32 board). I’m using the Arduino framework, but the compiler can’t find Preferences.h, included in WiFiManager:

 * WifiManager.h

#include <Arduino.h>
#include <Preferences.h>

The thing is, Preferences.h lives in the Arduino framework. On my machine at:

Arduino15⁩ ▸ ⁨packages⁩ ▸ ⁨esp32⁩ ▸ ⁨hardware⁩ ▸ ⁨esp32⁩ ▸ ⁨1.0.4⁩ ▸ ⁨libraries⁩ ▸ ⁨Preferences⁩ ▸ ⁨src⁩

so it should be included automatically when I select the platform/framework combination, yes?

My platformio.ini file has:

platform = espressif32
board = featheresp32
framework = arduino

lib_deps = 

I suspect the solution is obvious, but I don’t see it.

(Edited to remove superfluous libs – should be minimal, now.)

The Arduino-ESP32 framework is installed in the PlatformIO core directory C:\Users\<User>\.platformio\packages\framework-arduinoespressif32, from there, just like in the framework, follow the path to libraries\Preferences\src.

The header just declares the functions of the class. There should be no need to modify it.

Not reproducable with the given example sketch and your given platformio.ini.



Interesting. When I use your main.cpp, it compiles fine. But when I use my original one (which I didn’t include above – sorry), I get the error.

#include <Arduino.h>

void setup() {}
void loop() {}

So, I guess my misunderstanding is more fundamental than a library issue. Why do I need to explicitly #include <Preferences.h> in my main.cpp? Why doesn’t the WiFi manager code compile without it, even though those files include Preferences.h on their own?

Aha, okay so if the #include <Preferences.h> is burried in the WiFi manager code, then the library dependency finder might not pick it up (scans only your source files on the first level), unless you kick up the search mode per docs like

lib_ldf_mode = chain+

in the platformio.ini.

1 Like

Excellent. Thanks for the explanation!