Multiple definition of `rtc'

I just bought a MKR WIFI 1010 board to try out IoT. I got a lot to work in the first couple of days using the Iot Cloud editor.
My project is to turn on a driveway heater using the phone.
Turn on/off works fine but now I want to set a time for the heater to run. I have included the <RTZZero.h> lib and this is where things started to go wrong. I can't do much in the IoT cloud editor so I am stucked.

On compile I get this error:

Using library SNU at version 1.0.2 in folder: /home/builder/.arduino15/packages/arduino/hardware/samd/1.8.11/libraries/SNU

Using library adafruit_sleepydog_library_1_4_0 at version 1.4.0 in folder: /home/builder/opt/libraries/latest/adafruit_sleepydog_library_1_4_0

/tmp/962397445/build/libraries/arduinoiotcloud_1_1_1/utility/time/TimeService.cpp.o:/home/builder/opt/libraries/latest/arduinoiotcloud_1_1_1/src/utility/time/TimeService.cpp:33: multiple definition of `rtc'

/tmp/962397445/build/sketch/Driveway_Heater_aug03a.ino.cpp.o:/tmp/962397445/Driveway_Heater_aug03a/Driveway_Heater_aug03a.ino:26: first defined here

collect2: error: ld returned 1 exit status

exit status 1

1 Like

As I read this the TimeService.cpp is declared two times - so the problem is how to get rid of one og them - maybe that could solve the problem. But where are they?

I suggest you look at the examples of the RTZZoro.h library.

Think you mean RTZZero.h
That is exactly what is included. I don't have much code yet but only a decleration for a rtc object RTCZero rtc;
But then it won't compile....

I think the library you are using is for a SAMD21 not and ESP32. You should check you have the correct library. And every Arduino library has example code. You should find the example and verify all is operating before using your own code.

As stated in the top the board is MKR WIFI 1010 - this is a SAMD board. I am suspecting that maybe <ArduinoIotCloud.h> or something else also includes TimeService.cpp. If I am right it makes Arduino Iot Cloud unusable - you just choose the libraries you need and that is it. Maybe I will need to download these libraries and see if anything is declared twice. Then make a copy and upload a new version to my Sketch.

@peterol I think that the issue is because you're using both the RTCZero and Adafruit Sleepydog libraries. The former employs the RTC timer/counter, while the latter the WDT watchdog timer.

These libraries conflict, because they both try to configure their own 32.768kHz clock source on generic clock 2 (GCLK2), which clocks their respective timers.

RTCZero attempts configure SAMD21's GCLK2's source to be either the external 32.768kHz crystal (XOCS32K) or the on-chip internal 32.768kHz internal oscillator (OSC32K), (depending on whether the board is has an external crystal or not), while Sleepdog attempts to configure GCLK2 for the on-chip internal ultra low power 32.768kHz oscillator (OSCULP32K).

The workaround is to edit one of the libraries and move the clock source to say GCLK4, (GCLKs 0 to 3 are used by the Arduino core code).

OK thanks.
I can't see a reference to "Adafruit Sleepydog", Is it possible to get rid of Adafruit Sleepydog from my sketch?

I noticed your original post references it.

@peterol Digging a little deeper, it looks like the Arduino IoT Clound library already uses both the RTCZero and Adafruit Sleepydog libraries, which is why the Ardafruit Sleepydog library is being referenced in your compilation errors. Not being familiar with the Arduino IoT Cloud library, I'm not sure why they're using two incompatible libraries together?

The multiple definition of "rtc", is because the Arduino IoT library file: timesspace.cpp already defines (or creates) an RTCZero (C++) object called "rtc":

Therefore it's not possible to create another RTCZero object with the same name.

What do you have on line 26 of your sketch? Are you defining an rtc object there?

Yes I am. I will remove it to see what happens or rename it to rtc2.

Remove did not work but rename to rtc2 solved this problem. I am now close to end the software part - moving to hardware soon.
Thank you all for the help.
Regards Peter

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.