Mac OS X下的ldd工具——otool

在Linux系统中,ldd工具用于显示可执行文件依赖的动态库。然而,Mac OS X并不提供ldd。代替的是,可以使用otool来检查Mac上的动态库依赖。otool的-L选项能展示二进制文件所使用的共享库及其版本信息。这对于了解Mac应用程序的依赖关系至关重要。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

2014-05-11 wcdj


在Linux上确定系统的glibc版本,可以在shell中直接运行glibc共享库文件(将其视为可执行文件)来获取glibc的版本。这会输出各种文本信息,其中包括了glibc的版本号。

$/lib/libc.so.6
GNU C Library stable release version 2.4 (20101025), by Roland McGrath et al.
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Configured for i586-suse-linux.
Compiled by GNU CC version 4.1.2 20070115 (SUSE Linux).
Compiled on a Linux 2.6.16 system on 2010-10-25.
Available extensions:
        crypt add-on version 2.1 by Michael Glad and others
        GNU Libidn by Simon Josefsson
        GNU libio by Per Bothner
        NIS(YP)/NIS+ NSS modules 0.19 by Thorsten Kukuk
        NoVersion patch for broken glibc 2.0 binaries
        Native POSIX Threads Library by Ulrich Drepper et al
        BIND-8.2.3-T5B
Thread-local storage support included.
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>. 

$ldd --version
ldd (GNU libc) 2.4
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.

在某些Linux发行版中,GNU C函数库的路径并非/lib/libc.so.6。确定该库所在位置的方法是:针对某个与glibc动态链接的可执行文件,运行ldd程序,然后再检查输出的库依赖列表,便能发现glibc共享库的位置。

$ ldd myprog | grep libc

程序还可以调用函数gnu_get_libc_version(),来确定运行时的glibc版本。

#include <gnu/libc-version.h>

const char *gnu_get_libc_version(void);

但是在Mac上并没有ldd这个程序。

gerryyang@mba:wcdj$uname -a
Darwin mba.local 13.1.0 Darwin Kernel Version 13.1.0: Wed Apr  2 23:52:02 PDT 2014; root:xnu-2422.92.1~2/RELEASE_X86_64 x86_64 i386 MacBookAir5,2 Darwin
gerryyang@mba:wcdj$which ldd
gerryyang@mba:wcdj$ldd
-bash: ldd: command not found
gerryyang@mba:wcdj$locate libc.so

Where is ldd on Mac OS X

The Mac OS X equivalent of the Linux ldd command is otool -L. See the manage for more details, and checkout man dyld for more details.

See also:


otool - object file displaying tool

otool [ option ...  ] [ file ...  ]

       -L     Display the names and version numbers of  the  shared  libraries
              that  the object file uses.  As well as the shared library ID if
              the file is a shared library.

使用otool查看一个二进制程序:

gerryyang@mba:code_in_action$file pk
pk: Mach-O 64-bit executable x86_64
gerryyang@mba:code_in_action$otool -L pk
pk:
	/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 56.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
gerryyang@mba:lib$otool -L /usr/bin/which 
/usr/bin/which:
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)
gerryyang@mb

参考

[1] http://blog.client9.com/2012/06/02/what-is-ldd-on-mac-os-x.html




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值