Skip to content

Commit

Permalink
baselibc: Fix fflush duplicate error
Browse files Browse the repository at this point in the history
This tries to fix error:
Linking review/bin/targets/nordic_pca10056-auracast_usb/app/@apache-mynewt-nimble/apps/auracast_usb/auracast_usb.elf
Error: Arm GNU Toolchain arm-none-eabi/13.2 Rel1/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld.exe: Arm GNU Toolchain arm-none-eabi/13.2 Rel1/bin/../lib/gcc/arm-none-
eabi/13.2.1/thumb/v7e-m/nofp\libg.a(libc_a-fflush.o): in function `fflush':
fflush.c:(.text.fflush+0x0): multiple definition of `fflush'; review/bin/targets/nordic_pca10056-auracast_usb/app/@apache-mynewt-core/libc/baselibc/@apache-mynewt-core_libc_baselibc.a(mynewt.o):review/repos/apache-mynewt-core/libc/baselibc/src/mynewt.c:54: first defined here

fflush is not used anywhere in the code but for some reason gcc 12 and 13 complains about
duplicate. When baselibc version of fflush is removed code compiles and links without
problem and final elf does not have fflush from libc_a-fflush.o.

Since baselib.c fflush version is practically empty making it normal static
inline does not breaks anything and linker stops failing.
  • Loading branch information
kasjer committed Dec 12, 2023
1 parent da102f1 commit 234944f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions libc/baselibc/include/stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,15 @@ __extern_inline int putchar(int c)
#define getc(f) fgetc(f)
#define getchar() fgetc(stdin)

__extern_inline int fflush(FILE *stream)
/*
* GCC 12 and later complained about duplicate symbols when
* __extern_inline was used instead of static inline even though
* fflush was never put in final elf. This approach may be extended
* to other functions with __extern_inline in the future.
*/
static inline int fflush(FILE *stream)
{
return 0;
return 0;
}

__extern int printf(const char *, ...);
Expand Down

0 comments on commit 234944f

Please sign in to comment.