arduino-libraries / ArduinoBearSSL

Port of BearSSL to Arduino
MIT License
84 stars 49 forks source link

undefined reference to `_gettimeofday' when compiling on a Teensy4.0 #54

Closed gannaramu closed 2 years ago

gannaramu commented 2 years ago

I keep getting undefined reference to `_gettimeofday issue when importing the ArduinoBearSSL library.

undefined reference to `_gettimeofday'

Linking .pio\build\teensy40\firmware.elf
c:/users/ganna/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/lib/armv7e-m/fpu/fpv5-d16\libc.a(lib_a-gettimeofdayr.o): In function `_gettimeofday_r':
gettimeofdayr.c:(.text._gettimeofday_r+0x10): undefined reference to `_gettimeofday'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\teensy40\firmware.elf] Error 1

the fix mentioned https://github.com/arduino/Arduino/issues/9413 seems to solve it.

But wanted to understand the reason for this issue? any help is appreciated.

Thanks

aentinger commented 2 years ago

Imho this is something you should raise with @PaulStoffregen.

PaulStoffregen commented 2 years ago

I've put this on my list of issues to investigate.

Sorry, can't look at it right now. I'm working on 3 urgent projects, all behind schedule. :(

Jeroen88 commented 2 years ago

Maybe it has something to do with this line?

aentinger commented 2 years ago

It might be the case. Possible Teensy's platform defines cause BR_USE_UNIX_TIME to be set to 1 consequently requiring linking to _gettimeofday. In this case it would be as simple as adding a statement preventing this. @PaulStoffregen what would be a suitable define set in all Teensy platforms?

Jeroen88 commented 2 years ago

I do not know what compiler tag TEENSY defines, but in my port to the ESP32 I added

#if defined __unix__ || defined __linux__ || defined ESP32

and now it works like a charm.

My port to the ESP32 is here

gannaramu commented 2 years ago

I guess the teensy 4.x have the defines as:

#if defined(__IMXRT1052__) || defined(__IMXRT1062__)
PaulStoffregen commented 2 years ago

Added _gettimeofday to Teensy 4.x core library. https://github.com/PaulStoffregen/cores/commit/50342d77de1b495ee359e78c12153bb6532a5727

aentinger commented 2 years ago

Added _gettimeofday to Teensy 4.x core library. PaulStoffregen/cores@50342d7

Thank you :bow: