neu-rah / ArduinoMenu

Arduino generic menu/interactivity system
GNU Lesser General Public License v2.1
948 stars 191 forks source link

rotaryEvent example not compiling until I change .h -> Solution?? #382

Open UroSbre opened 2 years ago

UroSbre commented 2 years ago

Hello,

Example rotaryEvent doesn't want to compile and returns error:

C:\Users\Uroš\Documents\Arduino\DELUJOC_MENI2_mar12a\DELUJOC_MENI2_mar12a.ino: In function 'global constructors keyed to 65535_0_DELUJOC_MENI2_mar12a.ino.cpp.o': DELUJOC_MENI2_mar12a:64:1: error: variable 'fieldShadows0' with dynamic initialization put into program memory area DELUJOC_MENI2_mar12a:64:1: error: variable 'fieldShadows1' with dynamic initialization put into program memory area DELUJOC_MENI2_mar12a:64:1: error: variable 'mainMenuShadows' with dynamic initialization put into program memory area lto-wrapper.exe: fatal error: C:\Users\Uro�\Documents\ArduinoData\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-gcc returned 1 exit status compilation terminated. c:/users/uro�/documents/arduinodata/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/../lib/gcc/avr/7.3.0/../../../../avr/bin/ld.exe: error: lto-wrapper failed collect2.exe: error: ld returned 1 exit status exit status 1 variable 'fieldShadows0' with dynamic initialization put into program memory area

Since I am a total beginner at coding I was trying to figure out what part of the code triggers this error. To make long story short, by deliting parts of the program I found out that the error starts as soon as I add #include <menuIO/rotaryEventIn.h> to the code. Then by deliting code out of the header file I figured out that the error is cause by the this section of the header file:

// not sure where to put this..

template<class T> inline T operator~ (T a) { return (T)~(int)a; } template<class T> inline T operator| (T a, T b) { return (T)((int)a | (int)b); } template<class T> inline T operator& (T a, T b) { return (T)((int)a & (int)b); } template<class T> inline T operator^ (T a, T b) { return (T)((int)a ^ (int)b); } template<class T> inline T& operator|= (T& a, T b) { return (T&)((int&)a |= (int)b); } template<class T> inline T& operator&= (T& a, T b) { return (T&)((int&)a &= (int)b); } template<class T> inline T& operator^= (T& a, T b) { return (T&)((int&)a ^= (int)b); }

If I delit this part of code from the header, the program compiles and it seems that everything works fine, however, can anyone explain me what is the above code doing and why do we get that error. Thank you for explenation or suggestion how to fix the above part of the code.

UroSbre commented 2 years ago

I've done some more digging and found out that the error is caused only by one of those template<class T.....

template<class T> inline T operator| (T a, T b) { return (T)((int)a | (int)b); } <- if I comment this one the program complies successfully.