Getting multiple definition of `String const& EEPROMClass::put Errors

Status
Not open for further replies.

mjs513

Senior Member+
Afternoon all
Working on a new project that I described in this post: https://forum.pjrc.com/threads/59112-TeensyTimerTool?p=267831&viewfull=1#post267831 which is basically porting CommandStation-EX (https://github.com/DCC-EX/CommandStation-EX) that currently only supports Arduino Mega and Arduino Uno boards and is used for controlling locomotives that use dcc/dcc++. With some suggestions from @luni think I got the timers sorted out for the T3 and T4 but now getting a slew of errors of the type:
Code:
C:\Users\Merli\AppData\Local\Temp\arduino_build_405943\sketch\DCCEXParser.cpp.o: In function `String const& EEPROMClass::put<String>(int, String const&)':
[COLOR="#B22222"]F:\arduino-1.8.13-beta5\hardware\teensy\avr\libraries\EEPROM/EEPROM.h:167: multiple definition of `String const& EEPROMClass::put<String>(int, String const&)'
C:\Users\Merli\AppData\Local\Temp\arduino_build_405943\sketch\DCC.cpp.o:F:\arduino-1.8.13-beta5\hardware\teensy\avr\libraries\EEPROM/EEPROM.h:167: first defined here
f:/arduino-1.8.13-beta5/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions[/COLOR]

Here is a txt file of all the errors: View attachment Errors.txt

All the files referenced use EEProm put or get to read config data from the EEPROM and includes EEStore.h which has the include for EEPROM.h. The only other place the problem might be coming is from their StringFormatter class which not sure I did the defines correctly for but that looks like its more the their LCD Display driver which I am probably going to have rework eventually.

Any suggestions on where to look or what could be causing the conflict would be a help. And before anyone asks I am attaching a zip with the Sketch, its all self container the only extra thing you may need is @luni's TeensyTimerTool.
 

Attachments

  • CommandStation-EX.zip
    579.6 KB · Views: 57
Sorry, I may not be too much help when using those new fangled c++ things like templates ;) I am still more used to using stones and chisels :D

it is complaining by the different times the templates are being used from the EEPROM.h file

Building your sketch within sublimetext it shows the errors...
screenshot.jpg

Not sure if the issue is only in the StringFormatter class where send:
Code:
class StringFormatter
{
  public:
    static void send(Print * serial, const __FlashStringHelper* input...);
    static void send(Print & serial, const __FlashStringHelper* input...);
Or maybe it is because eeprom.h is included in multiple source files... or???
 
@luni - Thanks,

I sort of remembered having issues if two files included eeprom.h...

Example sketch:
Code:
#include <EEPROM.h>
extern void donothing();

int i=0;
void setup() {
 for (i=0 ; i<42 ;i++) { 
 pinMode(i,INPUT_PULLUP);
 }
} 
void loop() {
}
Some stupid secondary file:
Code:
#include <Arduino.h>
#include <EEPROM.h>

void donothing() {
  
}
And sure enough:
Code:
C:\Users\kurte\AppData\Local\Temp\arduino_build_166019\sketch\bar2.cpp.o: In function `String const& EEPROMClass::put<String>(int, String const&)':
C:\arduino-1.8.13\hardware\teensy\avr\libraries\EEPROM/EEPROM.h:167: multiple definition of `String& EEPROMClass::get<String>(int, String&)'
C:\Users\kurte\AppData\Local\Temp\arduino_build_166019\sketch\bar.ino.cpp.o:C:\arduino-1.8.13\hardware\teensy\avr\libraries\EEPROM/EEPROM.h:167: first defined here
collect2.exe: error: ld returned 1 exit status
 
Yes, the put/get string functions are declared/defined in a header. (They were added by some guy named luni a couple of month ago :( )
If more than one translation unit includes the header, the linker doesn't know which one to use. It therefore is necessary to declare functions defined in a header inline. BTW: :Inline is not so much a hint to the compiler to "inline" stuff but a directive which tells the linker that there is more than one definition of a function and all are the same. @MichaelMeissner can probably explain this much better than I :)
 
Afternoon all - just got back to the computer. Thanks for getting it resolved it was driving me nuts since there was only one place I could find that had EEProm.h directly called out. Everything was referencing back to that point.

As a check I downloaded @luni's copy of the CommandStation-EX as well as the version I was working on that was giving me a problem. Both compiled without an issue with the latest change to the EEPROM library that @PaulStoffregen made in Post #7. So it looks like the issue with EEPROM is put to bed.

Guess now the next step is to load it up and see what happens
 
Status
Not open for further replies.
Back
Top