Errors linking libresolv when building PHP 5.2.10 from source on OS X
-
05-07-2019 - |
Question
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.
Solution
Try adding -lresolv to your Makefile.
Hope this helps. I got the suggestion from this discussion.
OTHER TIPS
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.
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.
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.