PlatformIO Community

Include from header file doesn't work

Hello,

I work with the Arduino framework. I need to use EEPROM.h. It is located in:

.platformio/packages/framework-arduinoespressif32/libraries/EEPROM/src

My code is made of three files:

main.cpp
lib/EEPROMManager/EEPROMManager.cpp
lib/EEPROMManager/EEPROMManager.h

They all #include <EEPROM.h>. When I build:

lib/EEPROMManager/EEPROMManager.h:2:20: fatal error: EEPROM.h: No such file or directory

When I remove #include <EEPROM.h> from EEPROMManager.h, the build works.

In EEPROMManager.h, if I now include the full path:
#include "/home/myuser/.platformio/packages/framework-arduinoespressif32/libraries/EEPROM/src"
The build works.

In short, as soon as EEPROMManager.h includes EEPROM.h, the build fails. I do not understand why.
I checked c_cpp_properties.json, EEPROM.h is included.

It look like only header files (.h) can’t find EEPROM.h.

Is this include surrounded by any other #ifdefs in the library code?

No, but EEPROMManager.h does have an ifndef right after. Here’s the full file (minus class detail):

#include <Arduino.h>
#include <EEPROM.h>

#ifndef HEATPILOT_EEPROM
#define HEATPILOT_EEPROM

class EEPROMManager
{
    MY CLASS IS DEFINED HERE
};

#endif

Hm that’s very weird. Can you try adding

lib_deps = EEPROMManager

to the platformio.ini and show the library dependencies tree in the preamble of a verbose compilation? (pio run -v or Verbose Compile in the VSCode tasklist)

This didn’t fix the issue.
My file tree is actually a lot more complex than what I put in my original post. I tried to reproduce the issue in a new project with a simpler file structure, but it didn’t work.
So here’s my full dependency graph:

Dependency Graph
|-- <AWS_IOT> 1.0
|-- <ArduinoJson> 6.11.1
|-- <Commons>
|   |-- <EEPROMManager>
|   |   |-- <EEPROM> 1.0.3
|   |   |-- <ScheduleManager>
|   |   |   |-- <TimeManager>
|   |   |   |   |-- <NTPClient> 3.1.0
|   |   |   |   |-- <WiFi> 1.0
|   |   |   |   |-- <WiFiManager>
|   |   |   |   |   |-- <WiFi> 1.0
|   |-- <WiFiManager>
|   |   |-- <WiFi> 1.0
|-- <EEPROM> 1.0.3
|-- <EEPROMManager>
|   |-- <EEPROM> 1.0.3
|   |-- <ScheduleManager>
|   |   |-- <TimeManager>
|   |   |   |-- <NTPClient> 3.1.0
|   |   |   |-- <WiFi> 1.0
|   |   |   |-- <WiFiManager>
|   |   |   |   |-- <WiFi> 1.0
|-- <ScheduleManager>
|   |-- <TimeManager>
|   |   |-- <NTPClient> 3.1.0
|   |   |-- <WiFi> 1.0
|   |   |-- <WiFiManager>
|   |   |   |-- <WiFi> 1.0
|-- <TimeManager>
|   |-- <NTPClient> 3.1.0
|   |-- <WiFi> 1.0
|   |-- <WiFiManager>
|   |   |-- <WiFi> 1.0
|-- <UpdateManager>
|   |-- <HTTPUpdate> 1.3
|   |   |-- <HTTPClient> 1.2
|   |   |   |-- <WiFi> 1.0
|   |   |   |-- <WiFiClientSecure> 1.0
|   |   |   |   |-- <WiFi> 1.0
|   |   |-- <Update> 1.0
|   |   |-- <WiFi> 1.0
|   |-- <WiFi> 1.0
|-- <WebServer> 1.0
|   |-- <WiFi> 1.0
|   |-- <FS> 1.0
|-- <WiFiManager>
|   |-- <WiFi> 1.0

And the error messages caused by adding #include <EEPROM.h> to EEPROMManager.h:

In file included from lib/WiFiManager/WiFiManager.h:2:0,
                 from lib/WiFiManager/WiFiManager.cpp:3:
lib/EEPROMManager/EEPROMManager.h:2:20: fatal error: EEPROM.h: No such file or directory

****************************************************************
* Looking for EEPROM.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:EEPROM.h"
* Web  > https://platformio.org/lib/search?query=header:EEPROM.h
*
****************************************************************

compilation terminated.
*** [.pio/build/esp32dev/lib97c/WiFiManager/WiFiManager.cpp.o] Error 1
In file included from lib/WiFiManager/WiFiManager.h:2:0,
                 from lib/TimeManager/TimeManager.cpp:3:
lib/EEPROMManager/EEPROMManager.h:2:20: fatal error: EEPROM.h: No such file or directory

****************************************************************
* Looking for EEPROM.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:EEPROM.h"
* Web  > https://platformio.org/lib/search?query=header:EEPROM.h
*
****************************************************************

compilation terminated.
*** [.pio/build/esp32dev/lib6a6/TimeManager/TimeManager.cpp.o] Error 1
============================================================================= [FAILED] Took 10.04 seconds =============================================================================
The terminal process terminated with exit code: 1

By the way, thanks a lot for helping me with this.

|-- <EEPROM> 1.0.3 
|-- <EEPROMManager> 
|    |-- <EEPROM> 1.0.3

Hm so the dependency tree seems corect but the include is still not there. I’ll try to reproduce it in a minimal project.

1 Like

This is not reproducable for me in a minimal example.

platformio.ini

[env:esp32_eeprom]
platform = espressif32
board = esp32dev
framework = arduino

src\main.cpp

#include <Arduino.h>
#include <EEPROM.h>
#include <EEPROMManager.h>

#define LED_PIN A5

void setup() {
	pinMode(LED_PIN, OUTPUT);
	EEPROMManager::DoSomething();
}

void loop() {
	digitalWrite(LED_PIN, HIGH);
	delay(500);
	digitalWrite(LED_PIN, LOW);
	delay(500);
}

lib\EEPROMManager\EEPROMManager.h

#include <Arduino.h>
#include <EEPROM.h>

#ifndef LIB_EEPROMMANAGER_EEPROMMANAGER_H_
#define LIB_EEPROMMANAGER_EEPROMMANAGER_H_

class EEPROMManager {
public:
	EEPROMManager();
	virtual ~EEPROMManager();

	static void DoSomething();
};

#endif /* LIB_EEPROMMANAGER_EEPROMMANAGER_H_ */

lib\EEPROMManager\EEPROMManager.cpp

#include "EEPROMManager.h"

EEPROMManager::EEPROMManager() {}

EEPROMManager::~EEPROMManager() {}

void EEPROMManager::DoSomething() {
	EEPROM.write(0, 123);
}
Dependency Graph

|-- <EEPROM> 1.0.3 (C:\Users\Maxi\.platformio\packages\framework-arduinoespressif32\libraries\EEPROM)
|-- <EEPROMManager> (C:\Users\Maxi\Documents\stackoverflow_testing\lib\EEPROMManager)
|   |-- <EEPROM> 1.0.3 (C:\Users\Maxi\.platformio\packages\framework-arduinoespressif32\libraries\EEPROM)
[..]
DATA:    [          ]   4.7% (used 15396 bytes from 327680 bytes)
PROGRAM: [==        ]  16.5% (used 216236 bytes from 1310720 bytes)
[SUCCESS] Took 10.61 seconds 

Can you create the a project with just these files and attempt a compilation? Does an error occur?

I just did, and it works for me too:

Processing esp32dev (platform: espressif32; board: esp32dev; framework: arduino)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 1.11.0 > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: toolchain-xtensa32 2.50200.80 (5.2.0), framework-arduinoespressif32 2.10004.191002 (1.0.4), tool-esptoolpy 1.20600.0 (2.6.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 28 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <EEPROM> 1.0.3
|-- <EEPROMManager>
|   |-- <EEPROM> 1.0.3
Compiling .pio/build/esp32dev/src/main.cpp.o
Compiling .pio/build/esp32dev/libc0a/EEPROMManager/EEPROMManager.cpp.o
Archiving .pio/build/esp32dev/libc0a/libEEPROMManager.a
Indexing .pio/build/esp32dev/libc0a/libEEPROMManager.a
Linking .pio/build/esp32dev/firmware.elf
Building .pio/build/esp32dev/firmware.bin
Retrieving maximum program size .pio/build/esp32dev/firmware.elf
Checking size .pio/build/esp32dev/firmware.elf
Memory Usage -> http://bit.ly/pio-memory-usage
DATA:    [          ]   4.7% (used 15396 bytes from 327680 bytes)
PROGRAM: [==        ]  16.5% (used 216228 bytes from 1310720 bytes)
esptool.py v2.6
============================================================================= [SUCCESS] Took 4.70 seconds =============================================================================

This is all very confusing.

Then the minimal example has something that your non-working whole project does not. Are you able to upload the full project to github for reproduction?

Unfortunately I can’t, this is nonfree code… :confused:

I just noticed something odd: The dependency graph remains the same, whether it works or not.

It looks like this will all remain a mystery. For now, as a workaround, I can make it work including this in EEPROMManager.h:
#include “…/…/…/…/…/.platformio/packages/framework-arduinoespressif32/libraries/EEPROM/src/EEPROM.h”

If you could get a minimal project in which this error occurs this would be great. Maybe by partly porting back parts of the non-working project. Without reproducibility this is rather hard to fix :/.

Another way without having to hack in the include path in the source file is to add an -I flag with a static path to the library (which is a hack in itself…).

build_flags = -I C:/User/Username/.platformio/packages/framework-arduinoespressif32/libraries/EEPROM/src/EEPROM.h

in the platformio.ini. This will then be computer-specific sadly.

Thank you.

I will try to get to something shareable allowing the issue to be reproduced.

(I’m on a EU timezone, so it will be a few hours before I’m able to post an update.)

Looking at the error you mentioned before… I’d be looking at how it’s relates to WifiManager? Perhaps the header file is mentioned there inside a #ifdef conditional block?

I was able to make a minimal version allowing to reproduce the issue.

1 Like

Try to run in verbose mode

pio run -v
Warning! Circular dependencies detected between `/Users/ikravets/Downloads/Pio-10016-master/lib/ScheduleManager` and `/Users/ikravets/Downloads/Pio-10016-master/lib/EEPROMManager`
Warning! Circular dependencies detected between `/Users/ikravets/Downloads/Pio-10016-master/lib/WiFiManager` and `/Users/ikravets/Downloads/Pio-10016-master/lib/EEPROMManager`

Please open an issue here https://github.com/platformio/platformio-core/issues and we will investigate it.

1 Like