compile problems on Mac OS X (with XCode 1.2 and BIND9)

Christian Kreibich christian at whoop.org
Fri Jul 9 18:31:46 PDT 2004


Hi,


I looked into this today ... thank Brian for prodding me -- you owe me a
beer because fixing this was painful and nobody has donated a powerbook
so far :) 

On Mon, 2004-06-21 at 13:30, Ruoming Pang wrote:
> I am trying to compile Bro on a Mac OS X and encounter the following 
> two problems, both related to nb_dns.c:
> 
> The first is compile error. It is because the header file 
> arpa/nameser.h does not define HEADER, which is defined in 
> arpa/nameser_compat.h. nameser_compat.h will be included by nameser.h 
> only if BIND_8_COMPAT is defined, but I don't know if we should define 
> that. After including nameser_compat.h in nb_dns.c, it is able to 
> compile correctly.

[snip]

> Next came the link error:
> 
> ld: Undefined symbols:
> _res_9_dn_expand
> _res_9_init
> _res_9_mkquery
> _res_9_ns_initparse
> _res_9_ns_msg_getflag
> _res_9_ns_parserr
> 
> This is because libresolv is not linked. Looking at the configure 
> script reveals that it looks for libresolv.a, but only libresolv.dylib 
> is available. Just adding '-lresolv' to Makefile solves the problem.

Okay ... well what I see here is that if BIND_8_COMPAT is defined,
nameser8_compat.h is included (note the "8"), and that causes
nonblocking lookups to be disabled because nameser8_compat does not
define ns_msg.

What I'm doing in the attached patch is

1. check whether you're running Darwin
2. if so, test whether just including arpa/nameser.h gives you HEADER
3. if 2 fails, include arpa/nameser_compat.h and use -lresolv instead of
/usr/lib/libresolv.a

Just using -lresolv in general bombs on at least Linux. *sigh*.

Build tested on Darwin, Linux, FreeBSD. Apply with -p1. The patch also
contains a few comments for configure.ac, and removes duplicated ones
for OpenSSL checks.

Fingers crossed,
Christian.
-- 
________________________________________________________________________
                                          http://www.cl.cam.ac.uk/~cpk25
                                                    http://www.whoop.org

-------------- next part --------------
--- bro-pub-0.9a2/configure.ac	2004-05-24 13:13:57.000000000 -0700
+++ /home/cpk25/devel/bro-pub-0.9a2/configure.ac	2004-07-09 18:21:32.000000000 -0700
@@ -55,7 +55,10 @@
 
 AC_LBL_ENABLE_CHECK(brov6 activemapping expire-dfa-states mpatrol debug openssl)
 
-# Check for OpenSSL >= 0.9.7
+dnl ################################################
+dnl # OpenSSL
+dnl ################################################
+
 if test "$use_openssl" != "No"; then
     saved_libs="${LIBS}"
    	AC_CHECK_LIB(crypto, OPENSSL_add_all_algorithms_conf,
@@ -68,7 +71,6 @@
     LIBS="${saved_libs}"
 fi
 
-# Check that we have indeed >= 0.9.7 headers.
 if test "$use_openssl" != "No"; then
    saved_cflags="${CFLAGS}"
    CFLAGS="${CFLAGS} -I${OPENSSL}/include"
@@ -98,7 +100,7 @@
    )
 fi
 
-# Check for OpenSSL >= 0.9.7
+# Check for version >= 0.9.7
 if test "$use_openssl" = "Yes"; then
    saved_libs="${LIBS}"
    LIBS="${LIBS} -lssl -lcrypto"
@@ -118,9 +120,30 @@
 else
       AC_SUBST(WANT_SSL_OBJ, "")
 fi
+
+dnl ################################################
+dnl # OS-specific hacks and tweaks
+dnl ################################################
+
+dnl Specifying a specific resolver library seems to work/be necessary
+dnl on all OSs, but Darwin needs -lresolv instead of /usr/lib/libresolv.a
+dnl We define the default here and overwrite below. --ck
+bro_libresolv="/usr/lib/libresolv.a"
          
 case "$target_os" in
 
+darwin*)
+	AC_MSG_CHECKING([if we need to include arpa/nameser_compat.h])
+	AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[#include <arpa/nameser.h>]], [[HEADER *hdr;]]), bro_ns_header_defined=yes)
+	if test "z$bro_ns_header_defined" = x; then
+	   AC_MSG_RESULT(no)
+	else
+	   AC_DEFINE(NEED_NAMESER_COMPAT_H,,[Compatibility for Darwin])
+	   bro_libresolv="-lresolv"
+	   AC_MSG_RESULT(yes)
+	fi
+	;;
+
 linux*)
 	AC_MSG_CHECKING(Linux kernel version)
 	AC_CACHE_VAL(ac_cv_linux_vers,
@@ -134,7 +157,9 @@
 
 esac
 
-dnl Checks for programs.
+dnl ################################################
+dnl # Checks for programs
+dnl ################################################
 AC_PROG_YACC
 AC_PROG_CXX
 AC_PROG_LEX
@@ -158,7 +183,9 @@
 
 esac
 
-dnl Checks for header files.
+dnl ################################################
+dnl # Checks for header files.
+dnl ################################################
 AC_HEADER_STDC
 AC_LBL_TYPE_SIGNAL
 AC_LBL_CHECK_TYPE(int32_t, int)
@@ -196,7 +223,9 @@
 AC_BRO_SYSLOG_INT
 AC_BRO_SOCK_DECL
 
-dnl Checks for library functions.
+dnl ################################################
+dnl # Checks for library functions.
+dnl ################################################
 AC_LBL_LIBPCAP(V_PCAPDEP, V_INCLS)
 AC_CHECK_FUNCS(bpf_set_bufsize)
 AC_FUNC_MEMCMP
@@ -209,9 +238,9 @@
 AC_CHECK_LIB(resolv, ns_initparse, bro_ns_foo_works=yes)
 if test "x$bro_ns_foo_works" = x; then
    dnl Didn't work -- need to check manually if workaround works better
-   AC_MSG_CHECKING([for ns_initparse in /usr/lib/libresolv.a])
+   AC_MSG_CHECKING([for ns_initparse in resolver])
    saved_libs="${LIBS}"
-   LIBS="${LIBS} /usr/lib/libresolv.a"
+   LIBS="${LIBS} $bro_libresolv"
    AC_LINK_IFELSE(AC_LANG_PROGRAM([[#include <arpa/nameser.h>]], [[ns_initparse(0,0,0);]]), bro_ns_foo_static_works=yes)
 
    if test "x$bro_ns_foo_static_works" = x; then
--- bro-pub-0.9a2/nb_dns.c	2003-03-25 19:47:43.000000000 -0800
+++ /home/cpk25/devel/bro-pub-0.9a2/nb_dns.c	2004-07-09 17:57:53.000000000 -0700
@@ -41,6 +41,9 @@
 
 #include <arpa/inet.h>
 #include <arpa/nameser.h>
+#ifdef NEED_NAMESER_COMPAT_H
+#include <arpa/nameser_compat.h>
+#endif
 
 #include <errno.h>
 #ifdef HAVE_MEMORY_H


More information about the Bro mailing list