5

To begin with, I would normally opt to use a pre-compiled binary of PHP, but am required to build from source for a specific business need. (I'm not the type that compiles open-source apps just for kicks.)

I'm building on OS X 10.6 and am running into the following error when I try to make PHP 5.2.10 as an Apache module (--with-apxs2):

Undefined symbols:
  "_res_9_dn_expand", referenced from:
      _zif_dns_get_mx in dns.o
  "_res_9_search", referenced from:
      _zif_dns_get_mx in dns.o
      _zif_dns_check_record in dns.o
  "_res_9_dn_skipname", referenced from:
      _zif_dns_get_mx in dns.o
      _zif_dns_get_mx in dns.o
ld: symbol(s) not found

These symbols are part of libresolv, which is included at /usr/lib/libresolv.dylib on OS X (and has been since at least 10.4). Note that *.dylib files are the Mac equivalent of *.so files on Linux, and I've successfully compiled in libiconv.dylib already by passing --with-iconv=shared,/usr to ./configure, which eliminated similar linker errors for the iconv library.

When I run ./configure, it detects /usr/include/resolv.h and enables it in the makefile. However, I can't seem to figure out how to get the shared library to link in correctly. Any tips on getting that to work? I've never done anything like passing custom linker flags to ./configure, and Google has been no help to me for this problem, unfortunately.


Edit: I'm building from this TAR download if anyone wants to try to replicate the error on Snow Leopard.

4 Answers 4

4

Try adding -lresolv to your Makefile.

Hope this helps. I got the suggestion from this discussion.

5
  • That's a good lead. I just ran my compile script on a machine with 10.5 and it built just fine, so this is definitely a problem new to Snow Leopard. Unfortunately, I'm having trouble figuring out where to add -lresolv in the Makefile. (It would be even better if I can do something like set an environment variable and have ./configure add it for me.) MacPorts uses their own portfile format, so it isn't very helpful for specifics, unfortunately... Jul 30, 2009 at 14:41
  • 1
    Figured it out. I added if [ uname -r == "10.0.0" ]; then export EXTRA_LDFLAGS=-lresolv; fi before calling ./configure with the other options, and it successfully added -lresolv to the Makefile. I'm accepting this answer since it pointed me in the right direction. Thanks! Jul 30, 2009 at 15:57
  • I should note that since accepting this answer, I've updated my code to grab the kernel major version (10 in this case) using uname -r | cut -d . -f 1 instead. This is important because although OS X 10.6.0 has kernel version 10.0.0, OS X 10.6.2 has version 10.2.0, and so on. I now store this value to $KERNEL_MAJOR and use if [ $KERNEL_MAJOR -ge 10 ]; then ... fi to check for 10.6 or greater. Feb 25, 2010 at 21:57
  • Added export EXTRA_LDFLAGS=-lresolv before ./configure worked for me. Thanks a lot
    – Adi
    May 13, 2012 at 8:35
  • 1
    If EXTRA_LDFLAGS=-lresolv doesn't work, you can try adding "-lresolv" directly to the end of EXTRA_LIBS inside Makefile. If you don't see a line starting with EXTRA_LIBS, add it below the EXTENSION_DIR line like this: EXTRA_LIBS = -lresolv That worked for me.
    – Ray
    Jul 26, 2012 at 8:19
3

If you set the configure environment variable before running the configure script, you don't have to edit the makefile. For example:

LIBS=-lresolv ./configure --with-apxs2 --with-gd (etc.)

This solution worked for me.

2

I would recommend resolving the dependencies by using fink/macports. Build all the components using macports and then compile php from source pointing the lib dirs to /opt/...

You can even build php directly from source using macports.

1
  • Unfortunately, this isn't feasible, since the compiled binaries must be in a very specific custom location (i.e. not in /opt) and have minimal dependencies. In general though, a good suggestion. Jul 30, 2009 at 14:30
2

For those who can't figure out where to add -lresolv :)

Edit the Makefile, find line:

EXTRA_LIBS = [...lots of libs here...]

and add -lresolv to this line like this:

EXTRA_LIBS = -lresolv [...lots of libs here...]

Worked for me on MacOS X 10.6 Snow Leopard while compiling PHP for LiteSpeed.

1
  • Yeah, that would work too. I added a comment to the accepted answer above that will add this flag where needed before ./configure is run, and only on Snow Leopard. A bit easier (and more automatable) than hand tweaking. Aug 18, 2009 at 21:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.