Mac OS X下的ldd工具——otool

ZZ:http://blog.csdn.net/delphiwcdj/article/details/25541397


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

[plain]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. $/lib/libc.so.6  
  2. GNU C Library stable release version 2.4 (20101025), by Roland McGrath et al.  
  3. Copyright (C) 2006 Free Software Foundation, Inc.  
  4. This is free software; see the source for copying conditions.  
  5. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A  
  6. PARTICULAR PURPOSE.  
  7. Configured for i586-suse-linux.  
  8. Compiled by GNU CC version 4.1.2 20070115 (SUSE Linux).  
  9. Compiled on a Linux 2.6.16 system on 2010-10-25.  
  10. Available extensions:  
  11.         crypt add-on version 2.1 by Michael Glad and others  
  12.         GNU Libidn by Simon Josefsson  
  13.         GNU libio by Per Bothner  
  14.         NIS(YP)/NIS+ NSS modules 0.19 by Thorsten Kukuk  
  15.         NoVersion patch for broken glibc 2.0 binaries  
  16.         Native POSIX Threads Library by Ulrich Drepper et al  
  17.         BIND-8.2.3-T5B  
  18. Thread-local storage support included.  
  19. For bug reporting instructions, please see:  
  20. <http://www.gnu.org/software/libc/bugs.html>.   
  21.   
  22. $ldd --version  
  23. ldd (GNU libc) 2.4  
  24. Copyright (C) 2006 Free Software Foundation, Inc.  
  25. This is free software; see the source for copying conditions.  There is NO  
  26. warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
  27. 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版本。

[plain]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. #include <gnu/libc-version.h>  
  2.   
  3. const char *gnu_get_libc_version(void);  

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

[plain]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. gerryyang@mba:wcdj$uname -a  
  2. 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  
  3. gerryyang@mba:wcdj$which ldd  
  4. gerryyang@mba:wcdj$ldd  
  5. -bash: ldd: command not found  
  6. 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查看一个二进制程序:

[plain]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. gerryyang@mba:code_in_action$file pk  
  2. pk: Mach-O 64-bit executable x86_64  
  3. gerryyang@mba:code_in_action$otool -L pk  
  4. pk:  
  5.     /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 56.0.0)  
  6.     /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)  
  7. gerryyang@mba:lib$otool -L /usr/bin/which   
  8. /usr/bin/which:  
  9.     /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)  
  10. gerryyang@mb  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值