New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Name collision with MegaCoreX core #92
Comments
If you move the defines into the class, they will no longer collide with defines from other headers/libraries. It kind of looks like in this case the iom4808.h may be getting included first. i.e. cpp substitutes the define/macro string on the name of the symbol inside the class to muck up the symbol definition. |
Hi @bperrybap, |
Right, that is what I meant. Move/change the #defines to static const int declarations & definitions inside the class. However, and this is the big one. And it looks like there will be an issue for RTC_STATUS since it looks like iom4808.h is included prior to DS3232RTC.h In other words, you can prevent this code from causing name collision problems in other code but you can't modify this code to prevent other code from causing name collision problems for this code. i.e. if iom4808 is included before DS3232RTC.h |
Ah! I hadn't thought it through that far but I see what you mean. That could be a sticky issue in certain situations. Is this one of them though? Is iom4808.h likely to be directly included in many sketches? Am I thinking about that correctly? Having said that, I only just now installed the MegaCoreX and compiled several of the example sketches from the library without issue. So I don't know what's up with the OP's sketch. I haven't heard back from him; when I do I'll ask to see his sketch. In fact, if I do try
I suppose I could use the full path to the file if I really wanted to force the issue. |
@lmorris99 would you post your sketch please. |
@lmorris99 also, would you please try compiling the rtcTimeTemp example sketch and advise the results? |
A sketch is unlikely to include the offending header file. The way to test it is to build the DS3232RTC library with the specific board type that the OP used. Complicating things is that the IDE will now detect a "newer" version of the AVR gcc tools that may exist in the "packages" area that has been installed using the board manager. IMO, this is a VERY dumb thing to do and can cause all kinds of strange breakages, particularly when multiple versions of the IDE are installed. For example in my case I have 20+ versions of the IDE installed for testing purposes. If a core installs a new version of gcc tools, it can break things in other platforms/cores and in older IDE versions. I have tried to convince them more than once to abandon this capability but they refuse as they see it as a useful feature. This makes complete testing quite complicated nearly impossible since now you have test against not only a specific version of the IDE and board manager package for the selected board type, but also take into consider all the other board packages for compatible h/w architectures that may have bee installed since they may include their own tool set that might newer. i.e. if testing for AVR UNO you have to fully verify that there isn't an issue when other board packages are installed since those other board packages (even if not needed) can alter what s/w gets used when building for the UNO. And history has shown that even Arduino.cc can't even keep things straight. As they put out releases of the megaAVR package that has broken 100% of the ability to build code for the standard boards like UNO and Mega boards. |
I think I did that, and could not recreate the problem. Taking a cue from the iom4808.h file, I did make the assumption that the OP was compiling for ATmega4808; I will confirm if I hear back from him. At this point, unless we hear back from the OP and I can understand his issue better and hopefully reproduce it, I'll probably assume user error and close this issue. Although I have started cleaning up the #defines in the library, so I may as well follow through with that, it's well worthwhile. I agree that the ecosystem has become quite complex and with that comes risks. The proliferation of new boards and cores, while on the one hand is nice to see, brings a lot of baggage especially where different architectures are concerned. Most of the time I'm amazed that it works as well as it does. I gave up some time ago trying to keep up with it all. |
Nothing heard from OP, closing issue. |
I get the same warnings when building for boards in both the MegaCoreX and the megaAvr core. oddly enough it is just a warning and the code compiles and links. (Didn't try it as don't have the hardware) I wish that the Arduino IDE would ship using -Werror by default |
Hmm, now I can recreate the issue as well. Not sure what happened earlier. |
That was spot on. The only fix here appears to be renaming RTC_STATUS. That doesn't feel like a very satisfactory solution; more like whack-a-mole. Maybe something like DS32_STATUS. I suppose all the names should be consistent too. |
You could just undef it before your define for a quick fix. Then work on figuring out a better solution. One unfortunate issue is that if you move the symbols to const int inside the class, a name collision with a previous #define will create an error vs just a warning. |
I now have static constexpr uint8_t
DS32_ADDR {0x68}, // I2C device address
DS32_SECONDS {0x00}, // register addresses
DS32_MINUTES {0x01},
DS32_HOURS {0x02},
etc etc etc and I get a good compile for the ATmega4808. I didn't prefix the enums; I figure they are used more, so that would create more backwards compatibility issues. I think I'll just go with this and see what happens. I'll push my development branch to GitHub once I'm done testing and updating the documentation, in case you'd like to have a look. I appreciate all your input. I knew #define was evil but this is a good example of how bad it really is. The iom4808.h file has over 2000 #defines. What could possibly go wrong! |
The issue for low level AVR headers is that they are used in C modules which limits some of their alternatives. One thing to keep in mind is that constexpr is a C++ 11 thing which I think equates to gcc 4.8.1 There might be some old 3rd party less maintained cores like for some of the tiny AVRs that may use an older version of gcc. |
Jack, this thread seems vaguely similar to my problem - didn't want to open a new Issue, not sure of github etiquette ...
Using the Megacorex arduino core, i get this:
`
Users/lindsay/Documents/Arduino/libraries/DS3232RTC-master/src/DS3232RTC.cpp:70:0: warning: "RTC_STATUS" redefined
#define RTC_STATUS 0x0F
In file included from /Users/lindsay/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/avr/include/avr/io.h:691:0,
from /Users/lindsay/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/avr/include/avr/pgmspace.h:90,
from /Users/lindsay/Library/Arduino15/packages/MegaCoreX/hardware/megaavr/1.0.9/cores/coreX-corefiles/api/String.h:30,
from /Users/lindsay/Library/Arduino15/packages/MegaCoreX/hardware/megaavr/1.0.9/cores/coreX-corefiles/api/IPAddress.h:25,
from /Users/lindsay/Library/Arduino15/packages/MegaCoreX/hardware/megaavr/1.0.9/cores/coreX-corefiles/api/Client.h:22,
from /Users/lindsay/Library/Arduino15/packages/MegaCoreX/hardware/megaavr/1.0.9/cores/coreX-corefiles/api/ArduinoAPI.h:29,
from /Users/lindsay/Library/Arduino15/packages/MegaCoreX/hardware/megaavr/1.0.9/cores/coreX-corefiles/Arduino.h:23,
from /Users/lindsay/Library/Arduino15/packages/MegaCoreX/hardware/megaavr/1.0.9/libraries/Wire/src/Wire.h:25,
from /Users/lindsay/Documents/Arduino/libraries/DS3232RTC-master/src/DS3232RTC.cpp:31:
/Users/lindsay/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/avr/include/avr/iom4808.h:1979:0: note: this is the location of the previous definition
#define RTC_STATUS _SFR_MEM8(0x0141`
Do you have any wisdom for me? I appreciate your help.
Originally posted by @lmorris99 in #50 (comment)
The text was updated successfully, but these errors were encountered: