Linker error (embedding Lua on a Teensy 4.1)

maxime_andre

New member
Hi all,
i am trying to embed Lua 5.3.6 as an arduino library for different boards. Until now i have tested it on an esp32 dev module, and a pi pico, it works nice.
I would like it to support Teensy boards, especially the 4.1 since I am using it for a project of mine. But i have this linker error :

Code:
/home/maxime/.platformio/packages/toolchain-gccarmnoneeabi@1.50401.190816/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/lib/armv7e-m/fpu/fpv5-d16/libc.a(lib_a-openr.o): In function `_open_r':
openr.c:(.text._open_r+0x12): undefined reference to `_open'
/home/maxime/.platformio/packages/toolchain-gccarmnoneeabi@1.50401.190816/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/lib/armv7e-m/fpu/fpv5-d16/libc.a(lib_a-timesr.o): In function `_times_r':
timesr.c:(.text._times_r+0x2): undefined reference to `_times'
/home/maxime/.platformio/packages/toolchain-gccarmnoneeabi@1.50401.190816/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/lib/armv7e-m/fpu/fpv5-d16/libc.a(lib_a-unlinkr.o): In function `_unlink_r':
unlinkr.c:(.text._unlink_r+0xc): undefined reference to `_unlink'
/home/maxime/.platformio/packages/toolchain-gccarmnoneeabi@1.50401.190816/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'
/home/maxime/.platformio/packages/toolchain-gccarmnoneeabi@1.50401.190816/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/lib/armv7e-m/fpu/fpv5-d16/libc.a(lib_a-linkr.o): In function `_link_r':
linkr.c:(.text._link_r+0x10): undefined reference to `_link'
/home/maxime/.platformio/packages/toolchain-gccarmnoneeabi@1.50401.190816/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/lib/armv7e-m/fpu/fpv5-d16/libc.a(lib_a-signalr.o): In function `_getpid_r':
signalr.c:(.text._getpid_r+0x0): undefined reference to `_getpid'

I could provide some dummy functions (I have tried for _gettimeofday, it get rids of the error message, but i find that a little bit dirty. let me know what you think!)
I have also tried to remove some Lua module functions, particularly in "os". There are less errors, but "open", "times", and "gettimeofday" are still there.

The most difficult for me seems to be "_open", since it can be used for i/o as well as files i suppose.

Some informations:
- link to the repo : https://github.com/max22-/loar
- board : teensy 4.1
- software setup : PlatformIO with version 4.16.0 of the teensy platform (i have also tried with the arduino IDE, but same error)
- OS : Debian testing

Cheers
Maxime
 
Were you be able to fix this problem? I'm seeing it as well:

Code:
/home/folkert/.platformio/packages/toolchain-gccarmnoneeabi-teensy/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld: /home/folkert/.platformio/packages/toolchain-gccarmnoneeabi-teensy/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/lib/thumb/v7e-m+dp/hard/libc.a(libc_a-openr.o): in function `_open_r':
(.text._open_r+0x14): undefined reference to `_open'
 
Teensyduino has no open function because it doesn't support standard file I/O (only basic support for writing to stdout/stderr).
 
It’s possible to hook up a filesystem to your own definitions of _open(), _unlink(), etc. You’ll need your own filesystem, however. I use the “FS” filesystem interface that’s included with the Teensyduino core. You could plug in whatever implements that, for example, “LittleFS” or the SD card filesystem, etc.

Check out the newlib source for the correct function signatures. See libgloss/arm/syscalls.c.

Another option is to comment out the Lua functions/libraries that use these undefined functions. See lbaselib.c, linit.c, liolib.c, and possibly loslib.c. (I’m looking at the 5.4.4 source.) Perhaps start with commenting out the LUA_IOLIBNAME line in linit.c.
 
Last edited:
It’s possible to hook up a filesystem to your own definitions of _open(), _unlink(), etc. You’ll need your own filesystem, however. I use the “FS” filesystem interface that’s included with the Teensyduino core. You could plug in whatever implements that, for example, “LittleFS” or the SD card filesystem, etc.

Check out the newlib source for the correct function signatures. See libgloss/arm/syscalls.c.

Another option is to comment out the Lua functions/libraries that use these undefined functions. See lbaselib.c, linit.c, liolib.c, and possibly loslib.c. (I’m looking at the 5.4.4 source.) Perhaps start with commenting out the LUA_IOLIBNAME line in linit.c.
Could you elaborate a little more? I am getting a similar error (undefined reference to '_open') building LVGL and Lottie, and I'd be happy to start hacking away at files to stub out or implement this, but it's a bit beyond my expertise, as in - I don't even know which files to even edit :) Any further guidance would be appreciated!
 
Yeah, I did that :) It builds and links now. I just wondered if there was a more elegant way, like stubbing out an include file somewhere, or something that didn't make it a PITA to upgrade with future library updates. It's a 3rd party library (ThorVG) for playing Lotties that's modified and bundled with a 3rd party library (LVGL), so I don't have much control over the original source. Fortunately, you can set the input data via a hex encoded JSON string vs. reading JSON from a file, so it can still operate.
 
Back
Top