views:

1416

answers:

4

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.

+1  A: 

Try adding -lresolv to your Makefile.

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

Sean A.O. Harney
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...
Quinn Taylor
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!
Quinn Taylor
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.
Quinn Taylor
+1  A: 

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.

Shoan
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.
Quinn Taylor
+1  A: 

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.

VASMAN
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.
Quinn Taylor
+2  A: 

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.

chronon