ZZ:http://blog.csdn.net/delphiwcdj/article/details/25541397
在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