rdearman / twclone

A Clone of TradeWars BBS game.
GNU General Public License v2.0
11 stars 4 forks source link

Compilation Issue - GCC 12.2.1 - Fedora 37 - error: conflicting types for ‘getopt’ #1

Closed agatlin closed 1 year ago

agatlin commented 1 year ago

I am attempting to compile the code under GCC 12.2.1 on Fedora 37, but I am running into an issue.

Just as the instructions suggested, I ran ./configure followed by make. Here is the output from ./configure

(base) [anthony@fedora twclone]$ ./configure
loading cache ./config.cache
checking for a BSD compatible install... (cached) /usr/bin/install -c
checking whether build environment is sane... yes
checking for mawk... (cached) mawk
checking whether make sets ${MAKE}... (cached) yes
checking host system type... x86_64-unknown-linux-gnu
checking for a BSD compatible install... /usr/bin/install -c
checking for gcc... (cached) gcc
checking whether the C compiler (gcc  ) works... yes
checking whether the C compiler (gcc  ) is a cross-compiler... no
checking whether we are using GNU C... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for style of include used by make... GNU
checking dependency style of gcc... (cached) gcc3
checking for pow in -lm... (cached) yes
checking for pthread_create in -lpthread... (cached) yes
checking how to run the C preprocessor... (cached) gcc -E
checking for ANSI C header files... (cached) yes
checking for ctype.h... (cached) yes
checking for errno.h... (cached) yes
checking for math.h... (cached) yes
checking for netdb.h... (cached) yes
checking for netinet/in.h... (cached) yes
checking for pthread.h... (cached) yes
checking for stdio.h... (cached) yes
checking for stdlib.h... (cached) yes
checking for string.h... (cached) yes
checking for sys/ipc.h... (cached) yes
checking for sys/msg.h... (cached) yes
checking for sys/poll.h... (cached) yes
checking for sys/socket.h... (cached) yes
checking for sys/time.h... (cached) yes
checking for sys/types.h... (cached) yes
checking for termios.h... (cached) yes
checking for time.h... (cached) yes
checking for unistd.h... (cached) yes
creating ./config.status
creating Makefile
creating autoconf.h
autoconf.h is unchanged

Then here is the output from ./make with the 'getopt' related issue.

(base) [anthony@fedora twclone]$ make
make  all-am
make[1]: Entering directory '/home/anthony/Projects/twclone'
source='bigbang.c' object='bigbang.o' libtool=no \
depfile='.deps/bigbang.Po' tmpdepfile='.deps/bigbang.TPo' \
depmode=gcc3 /bin/sh ./depcomp \
gcc -DHAVE_CONFIG_H -I. -I. -I.     -g -O2 -c `test -f bigbang.c || echo './'`bigbang.c
In file included from bigbang.c:51:
./getopt.h:25:5: error: conflicting types for ‘getopt’; have ‘int(int,  char ** const,  const char *)’
   25 | int getopt (int, char **const, const char *);
      |     ^~~~~~
In file included from /usr/include/bits/getopt_posix.h:27,
                 from /usr/include/unistd.h:903,
                 from bigbang.c:50:
/usr/include/bits/getopt_core.h:91:12: note: previous declaration of ‘getopt’ with type ‘int(int,  char * const*, const char *)’
   91 | extern int getopt (int ___argc, char *const *___argv, const char *__shortopts)
      |            ^~~~~~
make[1]: *** [Makefile:369: bigbang.o] Error 1
make[1]: Leaving directory '/home/anthony/Projects/twclone'
make: *** [Makefile:255: all] Error 2

Do you happen to have any ideas on how to get around this?

It appears there is a custom version of getopt (getopt.h, getopt.c) that is used with bigbang.c for universe generation. Is this custom version of getopt necessary when running with a modern version of c? If not, what is the easiest way to disable it?

rdearman commented 1 year ago

I modified the configuration to remove the getops dependencies, it will now use the standard system getopt function. If you check out the latest version, it should compile. I am using Linux mint so can't test Fedora, but should be OK.

I haven't actually looked at this code in YEARS, so it took a little while to remember what and why I'd done it.

agatlin commented 1 year ago

Thank you, Rick! You certainly put a lot of work in this project. I wish I had found it years ago.

rdearman commented 1 year ago

Thank you, Rick! You certainly put a lot of work in this project. I wish I had found it years ago.

Actually, I rewrote a goodly portion of it (Bigbang mostly) in Rust. I haven't uploaded it to github. I probably should. But the rust stuff isn't supposed to be compatible with this. Also, just a note that the actual tradewars source code was released by the author a few years ago.