Multiple definition of `EEPROM` issue with my own MockEEPROM library

I am developing a project on the ESP8266/Arduino platform. But I really want to include unittesting for the native platform. For my project, I made a ConfigManager library that uses EEPROM to store config. To test this library, I need an EEPROM implementation for the native platform, which I made called MockEERPOM: lib/MockEEPROM/src · master · Dolf Andringa / aquaman · GitLab

I contains a MockEEPROMClass and a EEPROM.h file which only contains the following:

#ifndef EEPROM_h
#define EEPROM_h
#include <MockEEPROM.h>

MockEEPROMClass EEPROM;
#endif

The library.json file for it contains

{
...
"platforms": "native"
}

Now if I understand it correctly, platformio should automatically see the library, realize that it is needed for the platform and compile it and include it. And since there is no EEPROM.h for the native platform, there shouldn’t be an issue with multiple definitions. But for some reason, running the following test with platformio test -e native results in the following error:

/usr/bin/ld: .pio/build/native/libe9c/libConfigManager.a(ConfigManager.o):(.bss+0x0): multiple definition of `EEPROM'; .pio/build/native/test/test_desktop/test_configmanager.o:(.bss+0x0): first defined here

Any clues what I am doing wrong?

Sorry, I was being stupid, I put my MockEEPROMClass EEPROM statement in the header file instead of in the cpp file, and then declare and extern MockEEPROMClass EEPROM in the header file. With that, it works. Check my code on lib/MockEEPROM/src · master · Dolf Andringa / aquaman · GitLab to see the full version.

1 Like