Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 8 of 8

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

  1. #1
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    6,730

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

    Afternoon all
    Working on a new project that I described in this post: https://forum.pjrc.com/threads/59112...l=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&)':
    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
    Here is a txt file of all the errors: 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.
    Attached Files Attached Files

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    8,844
    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

    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...
    Click image for larger version. 

Name:	screenshot.jpg 
Views:	16 
Size:	87.5 KB 
ID:	23449

    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???

  3. #3
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,422
    The pull request I sent you this afternoon explains the error and a fix https://github.com/mjs513/CommandStation-EX/pull/1? A corresponding pull request for the fix in the EEProm is also done already (https://github.com/PaulStoffregen/EE...1e45a85c8c13db)

  4. #4
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,422
    The pull request I sent you this afternoon explains the error and a fix https://github.com/mjs513/CommandStation-EX/pull/1? A corresponding pull request for the fix in the EEProm library is also done already (https://github.com/PaulStoffregen/EE...1e45a85c8c13db)

  5. #5
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    8,844
    @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

  6. #6
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,422
    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 :-)

  7. #7
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,958
    Hopefully this fully resolves the problem?

    https://github.com/PaulStoffregen/EE...0c4482719021fe

  8. #8
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    6,730
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •