From c8c707d56946784ade2abce21409348287bc63cc Mon Sep 17 00:00:00 2001 From: rosenrost <52100845+rosenrost@users.noreply.github.com> Date: Mon, 16 Nov 2026 15:40:42 +0100 Subject: [PATCH] Avoid two definitions of getc() getc() was defined both in getc.c and as an alias of fgetc() in fgetc.c. Which one the linker picked depended on the order of the archive members, and pulling in both objects causes a "multiple definition" error. Use the alias with GCC and the function in getc.c only for other compilers. --- sources/fgetc.c | 2 ++ sources/getc.c | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/sources/fgetc.c b/sources/fgetc.c index 8a8e36e..d0abc1e 100644 --- a/sources/fgetc.c +++ b/sources/fgetc.c @@ -36,4 +36,6 @@ int fgetc(FILE *stream) } return ch; } +#ifdef __GNUC__ int getc(FILE *stream) __attribute__((alias("fgetc"))); +#endif diff --git a/sources/getc.c b/sources/getc.c index 39d51f1..2ba5762 100644 --- a/sources/getc.c +++ b/sources/getc.c @@ -1,6 +1,9 @@ #include +#ifndef __GNUC__ +/* with GCC, getc() is an alias of fgetc() defined in fgetc.c */ int getc(FILE *stream) { return fgetc(stream); -} \ No newline at end of file +} +#endif