Using the new Arduino IDE for ESP8266 and found bugs, report them here

Moderator: igrr

User avatar
By tuxedo0801
#40046 Hi there,

I'm (java expert, no c++ expert) trying to port a library from avr arduino to esp8266 arduino.

The library makes more or leass heavily use of static variables and class instances (singleton pattern).

I faced two problems:

1) duplicate method definition using templaes

I got the error:

Code: Select allerror: duplicate explicit instantiation of 'e_KnxDeviceStatus KnxDevice::read(byte, T&) [with T = unsigned char; byte = unsigned char]' [-fpermissive]
 template e_KnxDeviceStatus KnxDevice::read <unsigned char>(byte objectIndex, unsigned char& returnedValue);


Adding "-fpermissive" to the flags in platform.txt solved the issue:

compiler.cpreprocessor.flags=-fpermissive -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-I{compiler.sdk.path}/include"


Maybe the code can be modified to overcome this issue without adding the permissive flag. but as the avr arduino had no problems with it: How about adding this flag by default to the platform?

2) After solving the issue with the duplicate error, I faced this error:

/tmp/buildbb4fcaf6d0d53941d44b612db42cc988.tmp/sketch/KnxDevice_PushButton_with_Programming.ino.cpp.o:(.text._Z9knxEventsh+0x10): undefined reference to `e_KnxDeviceStatus KnxDevice::write<bool>(unsigned char, bool)'
/tmp/buildbb4fcaf6d0d53941d44b612db42cc988.tmp/sketch/KnxDevice_PushButton_with_Programming.ino.cpp.o: In function `knxEvents(unsigned char)':
/tmp/arduino_bb4fcaf6d0d53941d44b612db42cc988/KnxDevice_PushButton_with_Programming.ino:35: undefined reference to `e_KnxDeviceStatus KnxDevice::write<bool>(unsigned char, bool)'
/tmp/buildbb4fcaf6d0d53941d44b612db42cc988.tmp/libraries/KonnektingDeviceLibrary/KnxTpUart.cpp.o:(.text._ZN9KnxTpUart6RXTaskEv+0x14): undefined reference to `__cxa_guard_acquire'
/tmp/buildbb4fcaf6d0d53941d44b612db42cc988.tmp/libraries/KonnektingDeviceLibrary/KnxTpUart.cpp.o:(.text._ZN9KnxTpUart6RXTaskEv+0x18): undefined reference to `__cxa_guard_release'
/tmp/buildbb4fcaf6d0d53941d44b612db42cc988.tmp/libraries/KonnektingDeviceLibrary/KnxTpUart.cpp.o:(.text._ZN9KnxTpUart6RXTaskEv+0x37): undefined reference to `__cxa_guard_acquire'
/tmp/buildbb4fcaf6d0d53941d44b612db42cc988.tmp/libraries/KonnektingDeviceLibrary/KnxTpUart.cpp.o: In function `KnxTpUart::RXTask()':
/media/bigdisk/Programming/Arduino/Sketchbook/libraries/KonnektingDeviceLibrary/KnxTpUart.cpp:515: undefined reference to `__cxa_guard_release'
collect2: error: ld returned 1 exit status


I alread create an issue on github for both problems: https://github.com/esp8266/Arduino/issues/1498

User Links2004 pointed me to issue #500: https://github.com/esp8266/Arduino/issues/500

I compared the code example with my library, but did not find an exact pattern match.
I followed a link to related issue #574 where Links2004 suggested:

yes, replace all places where static is initialized by an function / or class in a function.
like this:

Code: Select allint EthernetClass::begin(uint8_t *mac_address)
{
  static DhcpClass s_dhcp;
in this specific case this will work:

static DhcpClass s_dhcp;
int EthernetClass::begin(uint8_t *mac_address)
{

but how to rework it can be different from static case to static case.


Changing the library accoring to this hint, would be equal to re-write the library. And that is not really practical.
Back on issue #500: User iggr stated.

Actually the original code is fine — C++ standard guarantees that local static initializer will be called exactly once, first time the function is executed. We just need to add __cxa_guard* implementations.


As I said at the beginning: I'm a Java expert, with little knowledge in C/C++. I have no idea what this "__cxa_guard* implementation" is about. All I found out: Those methods are defined in cxxabi.h, and a few of them are "dummy-implemented" in abi.cpp (https://github.com/esp8266/Arduino/blob ... 66/abi.cpp). Almost all of them will result in a "panic()" call... So, do they work? Or will the just throw a panic?

So, for my issue nr. 2): Is there a chance to get this solved (implement these methods to get the library working)? I would be glad if so. I even would donate to get this solved.

All further details can be found on my github issue: https://github.com/esp8266/Arduino/issues/1498

And if there is some information/detail missing: please let me know.

Best regards,
Alex