3

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?

3
  • This is gotta be a duplicate. I know how to answer this for GLibc. Basically, you can't, unless you want to ensure that your binary does not work. Commented May 11, 2019 at 16:01
  • Why is the C tag used? Commented May 11, 2019 at 16:02
  • 1
    @WeatherVane basically it is a C/C++ linking question and a generic one really. Commented May 11, 2019 at 16:05

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.