Page 1 of 1

undefined reference to `_fini'

Posted: Mon Aug 14, 2017 9:48 pm
by danw
Hi All,

I'm currently using ChibiStudio19 with GCC 6.3 and RT 17.6.0 on a STM32F765

When I try to use C++ classes like std::string and std::vector, I get the linker error:

Code: Select all

c:/chibistudio/tools/gnu tools arm embedded/6.3 2017q1/bin/../lib/gcc/arm-none-eabi/6.3.1/../../../../arm-none-eabi/lib/thumb/v7e-m/fpv5/hard\libg.a(lib_a-fini.o): In function `__libc_fini_array':
fini.c:(.text.__libc_fini_array+0x26): undefined reference to `_fini'
collect2.exe: error: ld returned 1 exit status

From what I gather, _fini() is run after main() which doesn't normally happen with a microcontroller. I can work around this by adding:

Code: Select all

__attribute__((used))
void _fini(void) { }

In syscalls.c. Is this the correct way to handle this? Are there any potential problems with this approach.

Thanks!

Re: undefined reference to `_fini'

Posted: Mon Aug 14, 2017 10:00 pm
by Giovanni
Hi,

I think you should provide it in your application because it is there that you decide what to do in that function, if anything.

Is the exact purpose documented somewhere? it is possible that the startup code should provide a "weak" stub implementation.

Edit: I only find references of those functions in association with shared libs which make no sense in an embedded system and labeled as obsolete anyway.

Giovanni

Re: undefined reference to `_fini'

Posted: Mon Aug 14, 2017 10:25 pm
by danw
Hi Giovanni,

Thank you for the fast reply. I haven't been able to find much documentation but also saw that it was obsolete.

I agree that it doesn't make sense so I'm not sure why GCC is trying to link against it. I will place the stub in my application for now and leave it at that.

Thanks!