From adadca1d93854745455e98d729eba13af166fd1c Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Sun, 25 Jul 2021 20:55:10 +0300 Subject: [PATCH] getopt_long.c: initialize optarg and optreset to avoid symbol clashes. this has been happening to me eg. with amiga clib2 like: /opt/cross_amigaos4/ppc-amigaos/SDK/clib2/lib/libc.a(unistd_getopt.o)(.text+0x0): In function `getopt': : multiple definition of `getopt' getopt_long.o(.text+0xc1c):/work/xmp-cli/src/getopt_long.c:481: first defined here /opt/cross_amigaos4/lib/gcc/ppc-amigaos/4.2.4/../../../../ppc-amigaos/bin/ld: Warning: size of symbol `getopt' changed from 16 in getopt_long.o to 672 in /opt/cross_amigaos4/ppc-amigaos/SDK/clib2/lib/libc.a(unistd_getopt.o) /opt/cross_amigaos4/ppc-amigaos/SDK/clib2/lib/libc.a(unistd_getopt.o)(.sdata+0x4): multiple definition of `optind' getopt_long.o(.sdata+0x4):/work/xmp-cli/src/getopt_long.c:133: first defined here /opt/cross_amigaos4/ppc-amigaos/SDK/clib2/lib/libc.a(unistd_getopt.o)(.sbss+0x0): multiple definition of `optopt' getopt_long.o(.sdata+0x8):/work/xmp-cli/src/getopt_long.c:126: first defined here /opt/cross_amigaos4/ppc-amigaos/SDK/clib2/lib/libc.a(unistd_getopt.o)(.sdata+0x0): multiple definition of `opterr' getopt_long.o(.sdata+0x0):/work/xmp-cli/src/getopt_long.c:126: first defined here --- src/getopt_long.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/getopt_long.c b/src/getopt_long.c index 260a78c..a64d721 100644 --- a/src/getopt_long.c +++ b/src/getopt_long.c @@ -60,8 +60,9 @@ int opterr = 1; /* if error message should be printed */ int optind = 1; /* index into parent argv vector */ int optopt = '?'; /* character checked for validity */ -int optreset; /* reset getopt */ -char *optarg; /* argument associated with option */ +/* initialize these two too to avoid symbol clashes from system libc: */ +int optreset = 0; /* reset getopt */ +char *optarg = NULL; /* argument associated with option */ #define PRINT_ERROR ((opterr) && (*options != ':'))