Hi guys,
Is it possible to have one declaration for several files?
I have this time.cpp:
#include <Arduino.h> #include <DS3231.h> DS3231 clock(SDA, SCL); String getTime() { clock.begin(); String result = String(clock.getDateStr()) + " "; result += String(clock.getTimeStr()); return result; } void setTime(uint8_t hour, uint8_t min, uint8_t sec, uint8_t date, uint8_t mon, uint16_t year) { clock.begin(); clock.setTime(hour, min, sec); clock.setDate(date, mon, year); }
It works.
But when I try to divide it into two different getTime.cpp and setTime.cpp with each function by file (first 5 lines of the declaration are in both files) I have the error:
pioenvs/megaatmega2560/src/setTime.cpp.o (symbol from plugin): In function `clock': (.text+0x0): multiple definition of `clock' .pioenvs/megaatmega2560/src/getTime.cpp.o (symbol from plugin):(.text+0x0): first defined here collect2: error: ld returned 1 exit status *** [.pioenvs/megaatmega2560/firmware.elf] Error 1
I understand the problem but have no idea how to solve this.