Go Down

Topic: trouble following library linking in general... but specifically with TimeLib.h  (Read 228 times) previous topic - next topic

the_orn

Running Arduino 1.8.9 for ESP8266 (2.5.2)

I'm trying to use TimeLib (//https://github.com/PaulStoffregen/Time) and Timezone (//https://github.com/JChristensen/Timezone).

But I'm running into linker problems. Output:

Code: [Select]

c:/users/rudy/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-3-20ed2b9/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: libraries\Timezone\Timezone.cpp.o:(.text._ZN8Timezone8toTime_tE14TimeChangeRulei+0x8): undefined reference to `makeTime(tmElements_t const&)'

c:/users/rudy/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-3-20ed2b9/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: libraries\Timezone\Timezone.cpp.o: in function `Timezone::toTime_t(TimeChangeRule, int)':

C:\Users\Rudy\Documents\Arduino\libraries\Timezone\src/Timezone.cpp:200: undefined reference to `makeTime(tmElements_t const&)'


I'm not sure why the linker isn't finding makeTime. I put pragma messages in to show that TimeLib.h is being include (it is) and that Time.cpp is compiling (it is).

The simplest program that replicates the link error is here:

Code: [Select]

#include <Timezone.h>

TimeChangeRule myDST = {"CDT", Second, Sun, Mar, 2, -240};    // Daylight time = UTC - 5 hours
TimeChangeRule mySTD = {"CST", First, Sun, Nov, 2, -300};     // Standard time = UTC - 6 hours
Timezone myTZ(myDST, mySTD);

void setup() {
  // put your setup code here, to run once:

  myTZ.locIsDST((time_t) 0);
}

void loop() {
  // put your main code here, to run repeatedly:

}


Thanks for any help!!
Rudy

the_orn

Update. Have downgraded to Arduino to 1.8.1. And the ESP8266 hardware to 2.2.0. I did this to try to replicate the results gotten here: https://www.arduinoslovakia.eu/blog/2017/7/esp8266---ntp-klient-a-letny-cas?lang=en

And their code is compiling with the same undefined reference:

Code: [Select]
c:/users/rudy/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-3-20ed2b9/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: libraries\Timezone\Timezone.cpp.o:(.text._ZN8Timezone8toTime_tE14TimeChangeRulei+0x8): undefined reference to `makeTime(tmElements_t const&)'

c:/users/rudy/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-3-20ed2b9/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: libraries\Timezone\Timezone.cpp.o: in function `Timezone::toTime_t(TimeChangeRule, int)':

C:\Users\Rudy\Documents\Arduino\libraries\Timezone\src/Timezone.cpp:200: undefined reference to `makeTime(tmElements_t const&)'

the_orn

Update and partial solution:

Okay, I found that the Time.cpp and TimeLib.h declarations differed:

Time.cpp:
Code: [Select]

time_t makeTime(tmElements_t &tm){ 


TimeLib.h (but NOT Time.h, which is theoretically identical...)
Code: [Select]

time_t makeTime(const tmElements_t &tm);  // convert time elements into time_


I removed the const and it compiled.

That actually makes sense to me, though I'm surprised it wasn't found sooner. On the off chance though, is there a configuration step that I missed?

I'll submit as a bug report to the Time project...

Go Up