How to debug missing libraries on macOS

dynamic libraryterminal

I'm trying to figure out why a binary isn't linking a shared library. On Linux the standard way to do this is LD_DEBUG=libs that shows the path of all linked libraries, but this isn't producing any output for me. I've read several articles recommending this on macOS, so was it removed or is there some trick to using it? I'm running on Catalina and I've tried both bash and zsh shells.

Example from macOS:

$ LD_DEBUG=libs uptime
19:18  up 10:06, 4 users, load averages: 2.00 2.21 2.04

Example from Linux:

$ LD_DEBUG=libs uptime
     25453: find library=libprocps.so.7 [0]; searching
     25453:  search cache=/etc/ld.so.cache
     25453:   trying file=/lib/arm-linux-gnueabihf/libprocps.so.7
     25453: 
     25453: find library=libdl.so.2 [0]; searching
     25453:  search cache=/etc/ld.so.cache
     25453:   trying file=/lib/arm-linux-gnueabihf/libdl.so.2
     25453: 
     25453: find library=libc.so.6 [0]; searching
     25453:  search cache=/etc/ld.so.cache
     25453:   trying file=/lib/arm-linux-gnueabihf/libc.so.6
     25453: 
     25453: find library=libsystemd.so.0 [0]; searching
     25453:  search cache=/etc/ld.so.cache
     25453:   trying file=/lib/arm-linux-gnueabihf/libsystemd.so.0
     25453: 
     25453: find library=librt.so.1 [0]; searching
     25453:  search cache=/etc/ld.so.cache
     25453:   trying file=/lib/arm-linux-gnueabihf/librt.so.1
     25453: 
     25453: find library=liblzma.so.5 [0]; searching
     25453:  search cache=/etc/ld.so.cache
     25453:   trying file=/lib/arm-linux-gnueabihf/liblzma.so.5
     25453: 
     25453: find library=liblz4.so.1 [0]; searching
     25453:  search cache=/etc/ld.so.cache
     25453:   trying file=/lib/arm-linux-gnueabihf/liblz4.so.1
     25453: 
     25453: find library=libgcrypt.so.20 [0]; searching
     25453:  search cache=/etc/ld.so.cache
     25453:   trying file=/lib/arm-linux-gnueabihf/libgcrypt.so.20
     25453: 
     25453: find library=libpthread.so.0 [0]; searching
     25453:  search cache=/etc/ld.so.cache
     25453:   trying file=/lib/arm-linux-gnueabihf/libpthread.so.0
     25453: 
     25453: find library=libgpg-error.so.0 [0]; searching
     25453:  search cache=/etc/ld.so.cache
     25453:   trying file=/lib/arm-linux-gnueabihf/libgpg-error.so.0
     25453: 
     25453: 
     25453: calling init: /lib/arm-linux-gnueabihf/libpthread.so.0
     25453: 
     25453: 
     25453: calling init: /lib/arm-linux-gnueabihf/libc.so.6
     25453: 
     25453: 
     25453: calling init: /lib/arm-linux-gnueabihf/libgpg-error.so.0
     25453: 
     25453: 
     25453: calling init: /lib/arm-linux-gnueabihf/libgcrypt.so.20
     25453: 
     25453: 
     25453: calling init: /lib/arm-linux-gnueabihf/liblz4.so.1
     25453: 
     25453: 
     25453: calling init: /lib/arm-linux-gnueabihf/liblzma.so.5
     25453: 
     25453: 
     25453: calling init: /lib/arm-linux-gnueabihf/librt.so.1
     25453: 
     25453: 
     25453: calling init: /lib/arm-linux-gnueabihf/libsystemd.so.0
     25453: 
     25453: 
     25453: calling init: /lib/arm-linux-gnueabihf/libdl.so.2
     25453: 
     25453: 
     25453: calling init: /lib/arm-linux-gnueabihf/libprocps.so.7
     25453: 
     25453: 
     25453: calling init: /usr/lib/arm-linux-gnueabihf/libarmmem-v7l.so
     25453: 
     25453: 
     25453: initialize program: uptime
     25453: 
     25453: 
     25453: transferring control: uptime
     25453: 
 19:17:22 up 22:36,  3 users,  load average: 0.00, 0.00, 0.00

Best Answer

Try this:

$ otool -L /usr/bin/uptime
/usr/bin/uptime:
    /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 1225.0.0)

(that's on macOS 10.11.6 but should work on newer versions)