Changing shared library information

2009-12-11

I needed to manage some GStreamer plugins’ shared library locations in their binary. I looked into using libtool but it’s incredibly complicated. Fortunately, it seems that Apple provides a very useful tool to achieve this on the command line.

If you’re the type to think “shared libraries? pssh, you mean install names!” then this is the tool for you (also, you’re weird). It’s called install_name_tool. You can add, remove or change a shared library entry.

For example, a library has the following otool -L output:

$ otool -L libwhatchamajig.so
libwhatchamajig.so:
    A/otherlib.so
    …

Let’s say we wanted to change otherlib’s location from A/ to B/. This can be achieved by running the following command:

install_name_tool -change A/otherlib.so B/otherlib.so libwhatchamajig.so

This will change the otherlib location, and it results in the following:

$ otool -L libwhatchamajig.so
libwhatchamajig.so:
    B/otherlib.so
    …

Definitely saved me a world of pain to otherwise manage these plugins automatically.