0

While trying to compile a MUD's codebase with make on an Ubuntu machine I get the following error:

comm.c:184:5: error: conflicting types for ‘gettimeofday’
  184 | int gettimeofday args( ( struct timeval *tp, struct timezone *tzp ) );
      |     ^~~~~~~~~~~~
In file included from comm.c:56:
/usr/include/x86_64-linux-gnu/sys/time.h:66:12: note: previous declaration of ‘gettimeofday’ was here
   66 | extern int gettimeofday (struct timeval *__restrict __tv,
      |            ^~~~~~~~~~~~

This is a code snippet from where the error comes from:

#if defined(linux)
/*int   accept      args( ( int s, struct sockaddr *addr, int *addrlen
) );*/
/*int   bind        args( ( int s, struct sockaddr *name, int namelen
) );*/
int close       args( ( int fd ) );
int gettimeofday    args( ( struct timeval *tp, struct timezone *tzp ) );
int listen      args( ( int s, int backlog ) );
int read        args( ( int fd, char *buf, int nbyte ) );
int select      args( ( int width, fd_set *readfds, fd_set *writefds,
                fd_set *exceptfds, struct timeval *timeout ) );
int socket      args( ( int domain, int type, int protocol ) );
int write       args( ( int fd, char *buf, int nbyte ) );
#endif

I've tried to remove the second parameter, but I get another error that says that there are too many arguments to the function 'gettimeofday'.

How do I fix this?

  • 3
    The program shouldn't be declaring those library functions on its own. It should instead be including the relevant system headers, e.g. `#include ` for `gettimeofday`. This code is either extremely old or badly written or both, so you may have a lot more work ahead to get it working on a modern system. – Nate Eldredge Jul 12 '21 at 18:10
  • 3
    It sounds like the system header is already included, so the quick fix is to just remove the declaration from your snippet entirely, or better, delete that entire section. – Nate Eldredge Jul 12 '21 at 18:12
  • It's old code — the C standard is over 30 years old, and there are few places where it is still necessary to adapt to either no prototypes (pre-standard C) or prototypes, and that's what the `args` macro does. The prototype for `read()` isn't accurate by modern standards either. – Jonathan Leffler Jul 12 '21 at 18:30
  • @NateEldredge has the solution. I deleted the unnecessary declarations and it worked. It still doesn't compile, so should I edit my question or close this one and open another if I need help later? Thank you for your help. – Lucas Aquino de Assis Jul 12 '21 at 18:37
  • 1
    @LucasAquinodeAssis I'd close this question and open a new one if the new problem is unrelated to conflicting external function declarations. – Tom Karzes Jul 12 '21 at 18:39

0 Answers0