Platform IO Arduino Compiler problem with multipel Files and apstract classes ESP 8266

Hey,
I am curently working on a Arduino (ESP 8266) programm that requerers the use of an abstract class that has a number of child classes. so far everything is working completly, but the main file is very convolutet. so i wantet to spit the file into ist classes. for this i thought i need to make a new .cpp file that links to the .h file that ist already there. but as soon as i even write a simple “Include Header1.h” statment in this new file i get lots and lots of erros in the linkin prozess that more or less point to the abstract class. If i try compiling with only one cpp and one .h file everything works perfectly fine. The .h file is protectet angainst multipel incusion.

PlatformIO core:5.1.1 Home 3.3.4 ESP8266 3.1.0

the error i get is this:
Linking .pio\build\nodemcu\firmware.elf
c:/users/fixiw/.platformio/packages/toolchain-xtensa/bin/…/lib/gcc/xtensa-lx106-elf/10.3.0/…/…/…/…/xtensa-lx106-elf/bin/ld.exe: .pio\build\nodemcu\src\main.cpp.o: in function _ZN13LED_InterfaceD2Ev': main.cpp:(.text._ZN13LED_InterfaceD2Ev+0x0): multiple definition of _ZN13LED_InterfaceD2Ev’; .pio\build\nodemcu\src\LED_snkae_one_collor.cpp.o:LED_snkae_one_collor.cpp:(.text._ZN13LED_InterfaceD2Ev+0x0): first defined here
c:/users/fixiw/.platformio/packages/toolchain-xtensa/bin/…/lib/gcc/xtensa-lx106-elf/10.3.0/…/…/…/…/xtensa-lx106-elf/bin/ld.exe: .pio\build\nodemcu\src\main.cpp.o: in function _ZN13LED_InterfaceD2Ev': main.cpp:(.text._ZN13LED_InterfaceD2Ev+0x0): multiple definition of _ZN13LED_InterfaceD1Ev’; .pio\build\nodemcu\src\LED_snkae_one_collor.cpp.o:LED_snkae_one_collor.cpp:(.text._ZN13LED_InterfaceD2Ev+0x0): first defined here
c:/users/fixiw/.platformio/packages/toolchain-xtensa/bin/…/lib/gcc/xtensa-lx106-elf/10.3.0/…/…/…/…/xtensa-lx106-elf/bin/ld.exe: .pio\build\nodemcu\src\main.cpp.o: in function _ZN13LED_InterfaceD0Ev': main.cpp:(.text._ZN13LED_InterfaceD0Ev+0x4): multiple definition of _ZN13LED_InterfaceD0Ev’; .pio\build\nodemcu\src\LED_snkae_one_collor.cpp.o:LED_snkae_one_collor.cpp:(.text._ZN13LED_InterfaceD0Ev+0x4): first defined here
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\nodemcu\firmware.elf] Error 1
==================================================================================== [FAILED] Took 3.75 seconds ====================================================================================

the code can by found here: https://github.com/FelixWurm/UniversalLEDInterface

Thanks in advance!

Demangled that says

multiple definition of LED_Interface::~LED_Interface()

You are declaring the destructor to be pure virtual at the same time as actually implementing it, I think that is causing some conflicts…

https://github.com/FelixWurm/UniversalLEDInterface/blob/2ca96f8dc062c9cc7da64b599aed4b9d0d1871ac/UniversalLEDInterface/include/Header1.h#L31-L45

Try deleting the implementation or the =0; part of the destructor.

Thanks a lot, i was lokking in a totaly different direction. i changed the code to this:

class LED_Interface {
public:
	LED_Interface(){};
	virtual ~LED_Interface(){};
	virtual void RUN(float time_ecapsed) = 0;
	virtual void adjust(int type, double value) = 0;
	/*
	virtual void trigger_set()
	virtual void stop_on_trigger();
	virtual void trigger_get(int type);
	*/
private:
};

//LED_Interface::~LED_Interface() {}

and now it semas to work like it should, however i may change virtual ~LED_Interface(){}; to ~LED_Interface(){}; cause i am not shure if it needs to by virtual.
Thanks for the quick help!!!

1 Like