I'm attempting to compile PHP from source on MacOS. I'm using the --enable-static configure option to build static libraries like this:
./configure --enable-static --disable-all
make
While this produces a working binary, if I inspect the binary with otool I can see that it's using two shared libraries, libresolv.9.dylib and libSystem.B.dylib:
$ otool -L sapi/cli/php
sapi/cli/php:
/usr/lib/libresolv.9.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.250.1)
Is there any way to statically link these libraries?
After researching this it sounds like it isn't possible or desirable to statically link libresolv and libSystem.
libSystem contains libc among other libraries. libresolv contains DNS functions such as res_init. Both are provided by MacOS. MacOS does not support static binaries.
Since these libraries are always available on MacOS it's ok to use them as a shared library.
If you need to support older versions of MacOS you can use the -mmacosx-version-min linker flag:
LDFLAGS="-mmacosx-version-min=10.7" ./configure --enable-static --disable-all
LDFLAGS="-mmacosx-version-min=10.7" make
You can confirm it worked by using otool -l and checking for LC_VERSION_MIN_MACOSX.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With