Conflicting Declaration in DS1307 library

I am a learning newcomer to Arduino. I am getting compilation errors when using the DS1307 libraries in version 1.0.1 of the IDE:

C:\Program-Arduino\arduino-1.0.1\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega2560 -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -IC:\Program-Arduino\arduino-1.0.1\hardware\arduino\cores\arduino -IC:\Program-Arduino\arduino-1.0.1\hardware\arduino\variants\mega -IC:\Program-Arduino\arduino-1.0.1\libraries\Wire -IC:\Program-Arduino\arduino-1.0.1\libraries\DS1307 C:\Users\Ric\AppData\Local\Temp\build7666495859859217241.tmp\DS1307.cpp -o C:\Users\Ric\AppData\Local\Temp\build7666495859859217241.tmp\DS1307.cpp.o
Using previously compiled: C:\Users\Ric\AppData\Local\Temp\build7666495859859217241.tmp\Wire\Wire.cpp.o
Using previously compiled: C:\Users\Ric\AppData\Local\Temp\build7666495859859217241.tmp\Wire\utility\twi.c.o
C:\Program-Arduino\arduino-1.0.1\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega2560 -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -IC:\Program-Arduino\arduino-1.0.1\hardware\arduino\cores\arduino -IC:\Program-Arduino\arduino-1.0.1\hardware\arduino\variants\mega -IC:\Program-Arduino\arduino-1.0.1\libraries\Wire -IC:\Program-Arduino\arduino-1.0.1\libraries\DS1307 -IC:\Program-Arduino\arduino-1.0.1\libraries\DS1307\utility C:\Program-Arduino\arduino-1.0.1\libraries\DS1307\DS1307.cpp -o C:\Users\Ric\AppData\Local\Temp\build7666495859859217241.tmp\DS1307\DS1307.cpp.o
In file included from C:\Program-Arduino\arduino-1.0.1\hardware\arduino\cores\arduino/Print.h:26,
from C:\Program-Arduino\arduino-1.0.1\hardware\arduino\cores\arduino/Stream.h:26,
from C:\Program-Arduino\arduino-1.0.1\libraries\Wire/../Wire/Wire.h:26,
from C:\Program-Arduino\arduino-1.0.1\libraries\DS1307\DS1307.cpp:2:
C:\Program-Arduino\arduino-1.0.1\hardware\arduino\cores\arduino/WString.h:116: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, const char*)' conflicts with
C:\Program-Arduino\arduino-1.0.1\hardware\arduino\cores\arduino/WString.h:115: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, const String&)' here
C:\Program-Arduino\arduino-1.0.1\hardware\arduino\cores\arduino/WString.h:116: warning: 'StringSumHelper& operator+(const StringSumHelper&, const char*)' is already a friend of class 'String'
C:\Program-Arduino\arduino-1.0.1\hardware\arduino\cores\arduino/WString.h:117: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, char)' conflicts with
C:\Program-Arduino\arduino-1.0.1\hardware\arduino\cores\arduino/WString.h:116: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, const char*)' here
C:\Program-Arduino\arduino-1.0.1\hardware\arduino\cores\arduino/WString.h:117: warning: 'StringSumHelper& operator+(const StringSumHelper&, char)' is already a friend of class 'String'
C:\Program-Arduino\arduino-1.0.1\hardware\arduino\cores\arduino/WString.h:118: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, unsigned char)' conflicts with
C:\Program-Arduino\arduino-1.0.1\hardware\arduino\cores\arduino/WString.h:117: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, char)' here
C:\Program-Arduino\arduino-1.0.1\hardware\arduino\cores\arduino/WString.h:118: warning: 'StringSumHelper& operator+(const StringSumHelper&, unsigned char)' is already a friend of class 'String'
C:\Program-Arduino\arduino-1.0.1\hardware\arduino\cores\arduino/WString.h:119: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, int)' conflicts with
C:\Program-Arduino\arduino-1.0.1\hardware\arduino\cores\arduino/WString.h:118: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, unsigned char)' here
C:\Program-Arduino\arduino-1.0.1\hardware\arduino\cores\arduino/WString.h:119: warning: 'StringSumHelper& operator+(const StringSumHelper&, int)' is already a friend of class 'String'
C:\Program-Arduino\arduino-1.0.1\hardware\arduino\cores\arduino/WString.h:120: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, unsigned int)' conflicts with
C:\Program-Arduino\arduino-1.0.1\hardware\arduino\cores\arduino/WString.h:119: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, int)' here
C:\Program-Arduino\arduino-1.0.1\hardware\arduino\cores\arduino/WString.h:120: warning: 'StringSumHelper& operator+(const StringSumHelper&, unsigned int)' is already a friend of class 'String'
C:\Program-Arduino\arduino-1.0.1\hardware\arduino\cores\arduino/WString.h:121: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, long int)' conflicts with
C:\Program-Arduino\arduino-1.0.1\hardware\arduino\cores\arduino/WString.h:120: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, unsigned int)' here
C:\Program-Arduino\arduino-1.0.1\hardware\arduino\cores\arduino/WString.h:121: warning: 'StringSumHelper& operator+(const StringSumHelper&, long int)' is already a friend of class 'String'
C:\Program-Arduino\arduino-1.0.1\hardware\arduino\cores\arduino/WString.h:122: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, long unsigned int)' conflicts with
C:\Program-Arduino\arduino-1.0.1\hardware\arduino\cores\arduino/WString.h:121: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, long int)' here
C:\Program-Arduino\arduino-1.0.1\hardware\arduino\cores\arduino/WString.h:122: warning: 'StringSumHelper& operator+(const StringSumHelper&, long unsigned int)' is already a friend of class 'String'
C:\Program-Arduino\arduino-1.0.1\libraries\DS1307\DS1307.cpp: In member function 'void DS1307::set(int, int)':
C:\Program-Arduino\arduino-1.0.1\libraries\DS1307\DS1307.cpp:97: warning: suggest parentheses around arithmetic in operand of |

The library files are from Google Code Archive - Long-term storage for Google Code Project Hosting.

Each has been modified to try and bring them up to compatibility with 1.0+ (this is something I am trying to do; accordingly I do not want to revert to 023).

The header code is attached.

#include <WConstants.h> has been changed to #include <Arduino.h>

The associated cpp file is also attached.

In the latterthere is no difference if I change the line:

#include <../Wire/Wire.h>

to

#include <Wire.h>

Other changes to the original cpp file (from the Google link) are to replace "Wire.send" with "Wire.write" and to replace "Wire.receive" with "Wire.read".

The sketch to test it all is attached:

The conflict appears to arise at lines 115 onwards in Wsring.h Yet I doubt this is the cause of the problem, more a symptom. Similarly the error highlighted in "void DS1307::set(int, int)" towards the end is probably not the issue either.
My two questions are: Can someone explain what is going wrong and why in this specific instance? Secondly. what is the general principle involving declarations within sketches where libraries themselves reference the same declarations and what approach would constitute good practice.

Thanks,
Ric

DS1307.ino (667 Bytes)

DS1307.h (1.33 KB)

DS1307.cpp (3.62 KB)

Unless this library has specific commands you need I would suggest a different library, something like GitHub - davidhbrown/RealTimeClockDS1307: Yet another DS1307 Real-Time Clock library for Arduino (obsolete) that I have used under 1.0 & 1.0.1 without problem.

Hi,
Thank you for your reply. The RTC library you pointed up is interesting. I haven't seen that particular one before and is one of very few that addresses the on-board memory supplied with some RTC boards.

I'm actually undertaking a review of many 1307 libraries, comparing approaches and documenting each. The DS1307 library referred to in this post is one of several - but the only one that I have been unable to get working in IDE 1.0+. I have successfully used DS1307RTC (now supplied with the examples in the current Arduino download) and DS1307new. I am also looking at SoftDS1307RTC.

It would be good to get the DS1307 working and perhaps for that I now ought to contact the author.

Regards,
Ric

I have altered the library and example program (attached) and they now compile under 1.0.1

DS1307.ino (468 Bytes)

DS1307.h (1.33 KB)

DS1307.cpp (3.43 KB)

Riva,
Many, many thanks. Yes it all compiles satisfactorily.

I have emailed the author and shall let him know about this thread should he reply.

Kind regards,
Ric

Riva, there is an error in the code you supplied for DS1307.cpp

As it stands the user will not be allowed to enter the 31st of the month:

  case DS1307_DATE:
    if(v<31 && v>-1)
    {
	rtc_bcd[DS1307_DATE]=((v / 10)<<4) + (v % 10);
    }
    break;

This should be changed to:

  case DS1307_DATE:
    if(v<32 && v>-1)
    {
	rtc_bcd[DS1307_DATE]=((v / 10)<<4) + (v % 10);
    }
    break;

This bug was first pointed out in 2009 here (http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1191209057/60) and should not be re-introduced.

Regards,
Ric

As I could not find a download on the google link you posted I went to the original thread and downloaded the files from there. I did not bother reading the thread so missed the bugfix :blush: