macOS上查看动态库依赖情况,ldd的替代工具otool

linux下,我们通常使用ldd命令查看可执行文件依赖了哪些动态库,以及程序运行时,这些动态库的位置。

比如我在我的centos测试服务器上查看nginx依赖的动态库:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
$ldd /usr/sbin/nginx
linux-vdso.so.1 => (0x00007ffe685de000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007fd364073000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fd363e57000)
libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007fd363c20000)
libpcre.so.1 => /lib64/libpcre.so.1 (0x00007fd3639be000)
libssl.so.10 => /lib64/libssl.so.10 (0x00007fd36374c000)
libcrypto.so.10 => /lib64/libcrypto.so.10 (0x00007fd3632eb000)
libz.so.1 => /lib64/libz.so.1 (0x00007fd3630d5000)
libprofiler.so.0 => /lib64/libprofiler.so.0 (0x00007fd362ec1000)
libc.so.6 => /lib64/libc.so.6 (0x00007fd362af4000)
/lib64/ld-linux-x86-64.so.2 (0x00007fd3645a8000)
libfreebl3.so => /lib64/libfreebl3.so (0x00007fd3628f1000)
libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007fd3626a4000)
libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007fd3623bb000)
libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007fd3621b7000)
libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007fd361f84000)
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007fd361c7d000)
libm.so.6 => /lib64/libm.so.6 (0x00007fd36197b000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fd361765000)
libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007fd361555000)
libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007fd361351000)
libresolv.so.2 => /lib64/libresolv.so.2 (0x00007fd361138000)
libselinux.so.1 => /lib64/libselinux.so.1 (0x00007fd360f11000)

MacOS没有ldd,可以通过otool -L命令达到统一的效果,比如:

1
2
3
4
5
$otool -L /usr/local/go/bin/go
/usr/local/go/bin/go:
/usr/lib/libSystem.B.dylib (compatibility version 0.0.0, current version 0.0.0)
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 0.0.0, current version 0.0.0)
/System/Library/Frameworks/Security.framework/Versions/A/Security (compatibility version 0.0.0, current version 0.0.0)

以及:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
$otool -L /usr/local/bin/ffmpeg
/usr/local/bin/ffmpeg:
/usr/local//lib/libavdevice.57.dylib (compatibility version 57.0.0, current version 57.10.100)
/usr/local//lib/libavfilter.6.dylib (compatibility version 6.0.0, current version 6.107.100)
/usr/local//lib/libavformat.57.dylib (compatibility version 57.0.0, current version 57.83.100)
/usr/local//lib/libavcodec.57.dylib (compatibility version 57.0.0, current version 57.107.100)
/usr/local//lib/libpostproc.54.dylib (compatibility version 54.0.0, current version 54.7.100)
/usr/local//lib/libswresample.2.dylib (compatibility version 2.0.0, current version 2.9.100)
/usr/local//lib/libswscale.4.dylib (compatibility version 4.0.0, current version 4.8.100)
/usr/local//lib/libavutil.55.dylib (compatibility version 55.0.0, current version 55.78.100)
/System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1259.0.0)
/System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo (compatibility version 1.2.0, current version 1.5.0)
/System/Library/Frameworks/CoreMedia.framework/Versions/A/CoreMedia (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1258.1.0)
/System/Library/Frameworks/VideoToolbox.framework/Versions/A/VideoToolbox (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/VideoDecodeAcceleration.framework/Versions/A/VideoDecodeAcceleration (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
/System/Library/Frameworks/Security.framework/Versions/A/Security (compatibility version 1.0.0, current version 57337.60.2)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)
/usr/lib/liblzma.5.dylib (compatibility version 6.0.0, current version 6.3.0)
/usr/lib/libbz2.1.0.dylib (compatibility version 1.0.0, current version 1.0.5)
/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 728.13.0)
/System/Library/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics (compatibility version 64.0.0, current version 600.0.0)
/System/Library/Frameworks/CoreImage.framework/Versions/A/CoreImage (compatibility version 1.0.1, current version 2.0.0)
/System/Library/Frameworks/AVFoundation.framework/Versions/A/AVFoundation (compatibility version 1.0.0, current version 2.0.0)
/System/Library/Frameworks/AudioToolbox.framework/Versions/A/AudioToolbox (compatibility version 1.0.0, current version 492.0.0)
/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1404.47.0)

参考链接:

本文完,作者yoko,尊重劳动人民成果,转载请注明原文出处: https://pengrl.com/p/20047/

0%