Hi guys,
I’m having trouble compiling my project using my MacBook, but on my PC I don’t have any errors.
On the Mac, I get the following error undefined reference to
SystemTime::rtc’`.
Here’s my platformio.ini
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:megaatmega1280]
platform = atmelavr
board = megaatmega1280
framework = arduino
lib_deps =
arduino-libraries/Ethernet@^2.0.0
knolleary/PubSubClient@^2.8
smfsw/Queue@^1.9.1
adafruit/RTClib@^1.13.0
paulstoffregen/Time@^1.6
bblanchon/ArduinoJson@^6.18.0
arduino-libraries/SD@^1.2.4
milesburton/DallasTemperature@^3.9.1
mulmer89/EZO I2C Sensors@1.0.0+32e1eda
[env:atmega2560]
board = megaatmega2560
platform = atmelavr
framework = arduino
lib_deps =
arduino-libraries/Ethernet@^2.0.0
knolleary/PubSubClient@^2.8
smfsw/Queue@^1.9.1
adafruit/RTClib@^1.13.0
paulstoffregen/Time@^1.6
bblanchon/ArduinoJson@^6.18.0
arduino-libraries/SD@^1.2.4
milesburton/DallasTemperature@^3.9.1
mulmer89/EZO I2C Sensors@1.0.0+32e1eda
Thanks
What code / library creates SystemTime::rtc? I did not see it in adafruit/RTClib
or paulstoffregen/Time
.
It’s my own wrapper class over RTClib.
Here’s the header code
///
/// \file SystemTime.h
/// \brief SystemTime Utility Peripheral module
/// \author Nicolas
///
#ifndef SYSTEMTIME_H_
#define SYSTEMTIME_H_
////////////////////////////////////////////////////////////////////////////////
// Includes
////////////////////////////////////////////////////////////////////////////////
#include <Arduino.h>
#include "RTClib.h"
#include "TypeDefs.h"
////////////////////////////////////////////////////////////////////////////////
// Definitions
////////////////////////////////////////////////////////////////////////////////
#define SYSTEMTIME_RTC_YEAR_MIN 2021 ///< Minimum RTC year (default at first startup).
#define SYSTEMTIME_RTC_YEAR_MAX 2200 ///< Maximum RTC year (virtual).
#define SYSTEMTIME_RTC_MONTH_MIN 1 ///< Minimum RTC month.
#define SYSTEMTIME_RTC_MONTH_MAX 12 ///< Maximum RTC month per year.
#define SYSTEMTIME_RTC_DAY_MIN 1 ///< Minimum RTC day.
#define SYSTEMTIME_RTC_DAY_MAX 31 ///< Maximum RTC day per month.
#define SYSTEMTIME_RTC_HOUR_MIN_24 0 ///< Minimum RTC hour (24h format).
#define SYSTEMTIME_RTC_HOUR_MAX_24 23 ///< Maximum RTC hour per day (24h format).
#define SYSTEMTIME_RTC_HOUR_MIN_12 1 ///< Minimum RTC hour (12h format).
#define SYSTEMTIME_RTC_HOUR_MAX_12 12 ///< Maximum RTC hour per day (12h format).
#define SYSTEMTIME_RTC_MINUTE_MIN 0 ///< Minimum RTC minute.
#define SYSTEMTIME_RTC_MINUTE_MAX 59 ///< Maximum RTC second per hour.
#define SYSTEMTIME_RTC_SECOND_MIN 0 ///< Minimum RTC second.
#define SYSTEMTIME_RTC_SECOND_MAX 59 ///< Maximum RTC second per minute.
#define TS_DEFAULT_FORMAT "YYYY-MM-DD hh:mm:ss"
#define TS_BUFFER_LENGTH 32
////////////////////////////////////////////////////////////////////////////////
// Type definitions
////////////////////////////////////////////////////////////////////////////////
//char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
////////////////////////////////////////////////////////////////////////////////
// Prototype
////////////////////////////////////////////////////////////////////////////////
class SystemTime {
public:
static void Init();
void Delay(unsigned long tick);
static uint32_t GetTimeDiff(uint32_t u32SysTimeToCompare);
static DateTime GetTime();
static void GetTimeString(char * sz);
static const char * GetTimeString();
static float GetTemperature(); // DS3231 Only
static DateTime GetStartTime();
static char* GetStartTimeString();
// RTC related.
bool RTCInit();
bool RTCIsInit();
bool RTCGetDate(uint16_t* pu16Year, uint8_t* pu8Month, uint8_t* pu8Day);
bool RTCGetTime(uint8_t* pu8Hour, uint8_t* pu8Minute, uint8_t* pu8Second);
bool RTCGetDateTime(uint16_t* pu16Year, uint8_t* pu8Month, uint8_t* pu8DayMonth, uint8_t* pu8Hour, uint8_t* pu8Minute, uint8_t* pu8Second);
bool RTCSetDate(uint16_t u16Year, uint8_t u8Month, uint8_t u8Day);
bool RTCSetTime(uint8_t u8Hour, uint8_t u8Minute, uint8_t u8Second);
static void RTCSetDateTime(uint16_t u16Year, uint8_t u8Month, uint8_t u8DayMonth, uint8_t u8Hour, uint8_t u8Minute, uint8_t u8Second);
static void RTCSetDateTime(const char *iso8601date);
private:
static bool isInitialized;
static RTC_DS3231 rtc;
static char cachedTime[TS_BUFFER_LENGTH];
static DateTime startTime;
static char startTimeString[TS_BUFFER_LENGTH];
};
#endif
Where is that file? In lib/<library name>
or in src/
?
What’s the file called?
(Usually if something compiles on Windows but not on Mac / Linux it’s because you’re choosing a file name that already exists but in another upper/lowercase spelling – Windows has a case-insensitive filesystem.)
The file is in the src/
folder. So basically the same folder as the main Application.cpp
.
Is it possible to upload the whole project, or a minimal reproduction of the problem? The bug seems hard to chase when not looking at the full picture.
Sure here’s the project zipped
But… there is no definition of the
RTC_DS3231 SystemTime::rtc;
variable at the top of SystemTime.cpp
? It does not even compile for me on Windows.
Linking .pio\build\atmega2560\firmware.elf
C:\Users\Max\AppData\Local\Temp\ccFlqkwL.ltrans0.ltrans.o: In function main': <artificial>:(.text.startup+0x860): undefined reference to
SystemTime::rtc’
:(.text.startup+0x864): undefined reference to SystemTime::rtc' <artificial>:(.text.startup+0x89a): undefined reference to
SystemTime::rtc’
:(.text.startup+0x89e): undefined reference to SystemTime::rtc' <artificial>:(.text.startup+0x8a6): undefined reference to
SystemTime::rtc’
C:\Users\Max\AppData\Local\Temp\ccFlqkwL.ltrans0.ltrans.o::(.text.startup+0x8aa): more undefined references to `SystemTime::rtc’ follow
Adding the afforementioned line solves the problem for me.
RAM: [===== ] 53.9% (used 4412 bytes from 8192 bytes)
Flash: [=== ] 27.5% (used 69852 bytes from 253952 bytes)
Building .pio\build\atmega2560\firmware.hex
===================== [SUCCESS] Took 24.09 seconds =====================
Likely you’re using some other version of the code or there’s some weird caching on the Windows machine involved if that code compiled there.
Wow! Such a beginner mistake. Thanks it worked!
But you’re right. It’s weird that it compiles on my Windows.