linux如何查看glibc版本信息多种方法

发布时间:2020-04-25编辑:脚本学堂
分享了linux下查看glibc版本信息的各种方法,rpm -qa | grep glibc是最为常用的查看glibc包的方法,也可以通过查看ls -l /lib/libc.so.6输出结果,详见文中教程。

教你如何查看当前系统的glibc版本?

查看glibc版本信息

centos(以centos 6.0为例):
(1) 可通过rpm -qa | grep glibc查看系统目前安装了哪些和glibc有关的包:
 

[root@Cluster ~]# rpm -qa | grep glibc
glibc-2.12-1.47.el6_2.12.i686
glibc-headers-2.12-1.47.el6_2.12.x86_64
glibc-common-2.12-1.47.el6_2.12.x86_64
glibc-devel-2.12-1.47.el6_2.12.x86_64
glibc-2.12-1.47.el6_2.12.x86_64
 

可以看到系统上glibc的版本号为2.12。

如果要进一步查看,可以通过rpm -qi glibc:
 

[root@Cluster ~]# rpm -qi glibc
Name : glibc Relocations: (not relocatable)
Version : 2.12 Vendor: CentOS
Release : 1.47.el6_2.12 Build Date: 2012年05月10日 星期四 16时11分39秒
Install Date: 2012年05月21日 星期一 17时46分08秒 Build Host: c6b5.bsys.dev.centos.org
Group : System Environment/Libraries Source RPM: glibc-2.12-1.47.el6_2.12.src.rpm
Size : 12871227 License: LGPLv2+ and LGPLv2+ with exceptions and GPLv2+
Signature : RSA/SHA1, 2012年05月10日 星期四 18时01分09秒, Key ID 0946fca2c105b9de
Packager : CentOS BuildSystem
URL : http://sources.redhat.com/glibc/
Summary : The GNU libc libraries
Description :
The glibc package contains standard libraries which are used by
multiple programs on the system. In order to save disk space and
memory, as well as to make upgrading easier, common system code is
kept in one place and shared between programs. This particular package
contains the most important sets of shared libraries: the standard C
library and the standard math library. Without these two libraries, a
linux system will not function.
 

 
(2) 也可以通过查看ls -l /lib/libc.so.6输出结果:
 

[root@Cluster ~]# ls -l /lib/libc.so.6
lrwxrwxrwx. 1 root root 12 5月 21 17:46 /lib/libc.so.6 -> libc-2.12.so
 

 
2  ubuntu(以ubuntu 11.04为例):
(1) 查看 ls -l /lib/i386-linux-gnu/libc.so.6的输出:
 

wzw@wzw-Lenovo:~$ ls -l /lib/i386-linux-gnu/libc.so.6
lrwxrwxrwx 1 root root 12 2012-07-15 09:14 /lib/i386-linux-gnu/libc.so.6 -> libc-2.13.so
 

(2) 也可以使用 apt-cache show libc6:
 

wzw@wzw-Lenovo:~$ apt-cache show libc6
Package: libc6
Priority: required
Section: libs
Installed-Size: 9456
Maintainer: Ubuntu Core developers
Original-Maintainer: GNU Libc Maintainers
Architecture: i386
Source: eglibc
Version: 2.13-0ubuntu13
Replaces: belocs-locales-bin, libc6-i386
Provides: glibc-2.13-1, libc6-i686
Depends: libc-bin (= 2.13-0ubuntu13), libgcc1, tzdata
Suggests: glibc-doc, debconf | debconf-2.0, locales
Conflicts: belocs-locales-bin, libc6-i686, prelink (<< 0.0.20090925), tzdata (<< 2007k-1), tzdata-etch
breaks: nscd (<< 2.13)
Filename: pool/main/e/eglibc/libc6_2.13-0ubuntu13_i386.deb
Size: 3764596
MD5sum: 1cfb03baf7c299fcf266f1c9b20c00a5
SHA1: 2f2d25e96ae7a8f9489a460154ffc31460b2dead
SHA256: c3336e5b6480591925974be5329eaa56a5632697eeb4a75de52905b3efd65e81
Description-zh_CN: Embedded GNU C Library: Shared libraries

本软件包包含了系统中几乎所有程序都会用到的标准运行库,包括标准 C 语言共享库和标准数学 库,以及许多其它的运行库。
Multi-Arch: same
Homepage: http://www.eglibc.org
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Origin: Ubuntu
Supported: 18m
Task: minimal
 
3 发行版无关方法:
(1) 查看ldd –version的输出结果:
 

wzw@wzw-Lenovo:~$ ldd –version
ldd (Ubuntu EGLIBC 2.13-0ubuntu13) 2.13
 

版权所有 (C) 2011 Free Software Foundation, Inc.
这是自由软件;请参考原始码的版权声明。本软件不提供任何担保,甚至不会包括可售性或适用于任何特定目的的担保。
由 Roland McGrath 和 Ulrich Drepper 编写。
 
(2) 编译执行如下程序:
 

#include
#include
int main(void)
{
puts(gnu_get_libc_version ());
return 0;
}
wzw@wzw-Lenovo:~$ ./a.out
2.13

linux下如何查看glibc的版本

对一下c二进制程序进行ldd,然后直接运行/lib/libc.so.?
 

root@xxx:/usr/local/memcached/bin# ldd memcached
        libevent-1.4.so.2 => /usr/lib/libevent-1.4.so.2 (0x40020000)
        libc.so.6 => /lib/libc.so.6 (0x40035000)
        libnsl.so.1 => /lib/libnsl.so.1 (0x40153000)
        librt.so.1 => /lib/librt.so.1 (0x40169000)
        libresolv.so.2 => /lib/libresolv.so.2 (0x4017c000)
        /lib/ld-linux.so.2 (0x40000000)
        libpthread.so.0 => /lib/libpthread.so.0 (0x4018f000)
root@xxx:/usr/local/memcached/bin# /lib/libc.so.6
GNU C Library stable release version 2.3.4, by Roland McGrath et al.
Copyright (C) 2004 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.
Compiled by GNU CC version 3.3.4.
Compiled on a Linux 2.4.29 system on 2005-01-28.
Available extensions:
        GNU libio by Per Bothner
        crypt add-on version 2.1 by Michael Glad and others
        GNU Libidn by Simon Josefsson
        linuxthreads-0.10 by Xavier Leroy
        BIND-8.2.3-T5B
        libthread_db work sponsored by Alpha Processor Inc
        NIS(YP)/NIS+ NSS modules 0.19 by Thorsten Kukuk
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.

注意跟gcc版本是不一样的, gcc是linux下的c编译器.
 

root@xxx:/usr/local/memcached/bin# gcc --version
gcc (GCC) 3.3.4
Copyright (C) 2003 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
 

 
另一个方法:
 

slackware:
# ls /var/log/packages | grep glibc
suse/redhat:
# getconf -a |grep glib -i

查看当前系统的glibc版本

查看当前系统的glibc版本,可以这样查看:
/lib/libc.so.6

有时:/lib/x86-64-linux/libc.so.6
把这个文件当命令执行下。

为什么这个库可以直接run呢? 原来在libc的代码中有一点小手脚:
 

Makerules:586:LDFLAGS-c.so += -e __libc_main
csu/version.c:71:__libc_main (void)

void
__libc_main (void)
{
  __libc_print_version ();
  _exit (0);

}
 

或者:

因为ldd命令也是glibc提供的,所以也能查看
 

ldd  --version

glibc是什么,以及与gcc的关系?
glibc是gnu发布的libc库,也即c运行库。
glibc是linux 系统中最底层的api(应用程序开发接口),几乎其它任何的运行库都会倚赖于glibc。
glibc除了封装linux操作系统所提供的系统服务外,它本身也提供了许多其它一些必要功能服务的实现,主要的如下:
(1)string,字符串处理
(2)signal,信号处理
(3)dlfcn,管理共享库的动态加载
(4)direct,文件目录操作
(5)elf,共享库的动态加载器,也即interpreter
(6)iconv,不同字符集的编码转换
(7)inet,socket接口的实现
(8)intl,国际化,也即gettext的实现
(9)io
(10)linuxthreads
(11)locale,本地化
(12)login,虚拟终端设备的管理,及系统的安全访问
(13)malloc,动态内存的分配与管理
(14)nis
(15)stdlib,其它基本功能
gcc 是编译器,基本上 Linux 下所有的程序(包括内核)都是 gcc 编译的,libc 当然也是。
gcc 和 libc 是互相依赖的两个软件,它们合作的方式类似 Linux 系统的 "自举"。先在一个可以运行的带有老 libc 和 gcc 的系统上,用老 gcc 编译出一个新版本的 gcc + 老 libc,再用这个新 gcc 编译出一个新 gcc + 新 libc,再用这套东东编译整个新系统。

glibc版本查看

4.9. How can I find out which version of glibc I am using in the moment? {UD} If you want to find out about the version from the command line simply run the libc binary. This is probably not possible on all platforms but where it is simply locate the libc DSO and start it as an application. On Linux like /lib/libc.so.6 This will produce all the information you need. What always will work is to use the API glibc provides. Compile and run the following little program to get the version information: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #include <stdio.h> #include <gnu/libc-version.h> int main (void) { puts (gnu_get_libc_version ()); return 0; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This interface can also obviously be used to perform tests at runtime if this should be necessary.

Just execute:
ldd --version

which comes with glibc package

查看Linux上glibc的版本 

1、ldd命令
 

virtualBox:/lib # ldd --version
ldd (GNU libc) 2.11.3
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
.......

2、直接运行libc.so.6
 

virtualBox:/lib # /lib/libc.so.6
GNU C Library stable release version 2.11.3 (20110527), by Roland McGrath et al.
Copyright (C) 2009 Free Software Foundation, Inc.