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.

Now fflush is weak so linker will take other version when needed.
This is workaround till batter solution is found.
  • Loading branch information
kasjer committed Dec 13, 2023
1 parent da102f1 commit 85d8454
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 1 addition & 4 deletions libc/baselibc/include/stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,7 @@ __extern_inline int putchar(int c)
#define getc(f) fgetc(f)
#define getchar() fgetc(stdin)

__extern_inline int fflush(FILE *stream)
{
return 0;
}
__extern int fflush(FILE *stream);

__extern int printf(const char *, ...);
__extern int vprintf(const char *, va_list);
Expand Down
6 changes: 6 additions & 0 deletions libc/baselibc/src/mynewt.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ struct File *const stdin = &_stdin;
struct File *const stdout = &_stdin;
struct File *const stderr = &_stdin;

int __attribute__((weak))
fflush(FILE *stream)
{
return 0;
}

#if MYNEWT_VAL(BASELIBC_THREAD_SAFE_HEAP_ALLOCATION)

static struct os_mutex heap_mutex;
Expand Down

0 comments on commit 85d8454

Please sign in to comment.