Skip to main content
Visitor II
September 9, 2021
Question

Newlib Nano link failure for _fstat and _isatty: Other functions link fine.

  • September 9, 2021
  • 1 reply
  • 3083 views

I'm trying to migrate a project from HAL back to SPL as it's less of a haul than porting our code I have to integrate to HAL. The HAL program compiled but at some point during my porting process I'm now getting link errors ONLY for _fstat and _isatty, not any of the other functions defined in the assert.c

The assert.c is the same between a working SPL based project we have and the new one I'm creating, so nothing has changed there. If I implement _fstat in my main.c it still complains that it can't link.

Linker Error:

c:/program files (x86)/gnu arm embedded toolchain/10 2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld.exe: c:/program files (x86)/gnu arm embedded toolchain/10 2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m+dp/hard\libg_nano.a(lib_a-fstatr.o): in function `_fstat_r':

fstatr.c:(.text._fstat_r+0xe): undefined reference to `_fstat'

I've also tried changing and linking against the soft-fp version of the library with no change.

From main.c:

#include <sys/stat.h>

int _fstat (int fd, struct stat* st)

{

 memset (st, 0, sizeof(*st));

 return _swistat (fd, st);

}

    This topic has been closed for replies.

    1 reply

    Super User
    September 9, 2021

    These are system calls. They should be in "syscalls.c" in your project somewhere, not in the newlib library. If you generate code with CubeMX, it will generate them.

    LMore.5Author
    Visitor II
    September 9, 2021

    Yes, they are in "syscalls.c" but the newlib nano links against their implementations. For some reason the linker isn't finding the definitions in the syscalls.c or even if I override them in my main.c (as they are declared as __attribute__(weak) to allow overriding in other code)

    Explorer II
    February 23, 2024