DALnet / bahamut

The Bahamut IRC Daemon
http://www.dal.net/?page=Bahamut
Other
57 stars 42 forks source link

Bundled system headers are not compatible with macOS #230

Open ryandesign opened 1 year ago

ryandesign commented 1 year ago

Compiling bahamut fails on macOS 12.6.7 (and other versions) when linking ircd:

Undefined symbols for architecture x86_64:
  "_res_mkquery", referenced from:
      _query_name in res.o
ld: symbol(s) not found for architecture x86_64

This problem was previously reported to MacPorts for version 2.0.7 back in 2014 but the problem remains with version 2.2.2.

One problem is that the -lresolv flag has not been supplied to the linker due to #229. Working around that is necessary but not sufficient to fix this issue.

As explained in #229, the symbol name in libresolv on macOS is not _res_mkquery but _res_9_mkquery, and getting this to work requires that the resolv.h header be included.

res.c does include resolv.h, but includes the local copy of resolv.h in bahamut's include directory. The include directory contains some other local copies of system headers: inet.h, nameser.h, queue.h, and cdefs.h (which doesn't even appear to be used anywhere). Trying to use these local non-macOS-compatible versions of system headers is the problem; deleting them and fixing everything to use the real system headers solved the problem for me. To get it to build, I did the following:

Change this... ...to this:
#include "inet.h" #include <arpa/inet.h>
#include "nameser.h" #include <arpa/nameser.h>
#include "queue.h" #include <sys/queue.h>
#include "resolv.h" #include
--- src/res.c.orig
+++ src/res.c
@@ -58,15 +58,6 @@

 #define RES_HOSTLEN 127 /* big enough to handle addresses in in6.arpa */

-extern int  dn_expand(char *, char *, char *, char *, int);
-extern int  dn_skipname(char *, char *);
-extern int
-res_mkquery(int, char *, int, int, char *, int,
-       struct rrec *, char *, int);
-
-#ifndef AIX
-extern int  errno, h_errno;
-#endif
 extern int  highest_fd;
 extern aClient *local[];

I'm not sure why bahamut has local copies of system headers. They've been there ever since the initial import into this repository in 1999. I can speculate that back then, some operating systems may have had broken system headers and that bahamut was attempting to provide fixed versions. If you don't need to support those old systems anymore, I suggest deleting the bundled system headers and fixing things up as indicated. If you do still need to support old systems, is there a way that you could use the local system headers only on those old systems so that modern systems are not impacted?