samdze / playdate-nim

Nim bindings with extra features for the Playdate SDK
66 stars 3 forks source link

Build for device OS 2.0 error: undefined reference to `_fini' #12

Closed samdze closed 1 year ago

samdze commented 1 year ago

Playdate OS 2.0 brought some changes to how C games are built. This unexpectedly made the example Nim project unable to compile.

This is the error the compiler outputs:

...
fini.c:(.text.__libc_fini_array+0x20): undefined reference to `_fini'
collect2: error: ld returned 1 exit status
make: *** [build/pdex.elf] Error 1

Workaround: manually defining and exporting to C a _fini function somewhere in the codebase fixes the issue:

proc fini() {.cdecl, exportc: "_fini".} =
    discard

The error seems to be caused by Nim generating C code that calls exit, which is not supported by the Playdate. The exit calls generated by Nim seem related to exception handling.

samdze commented 1 year ago

Fixed by c29791821d8f4f205bc33f2de0a08797fb4d1e7f