查询Linux系统中glibc的版本

编写一个简单的程序

#include <stdio.h>
int main()
{
        printf("Hello world
");
        return 0;
}

编译

gcc test.c

查看glibc的位置

ldd a.out | grep libc

在我的机器上显示

libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb757a000)

直接运行glibc共享库文件查看版本

$ /lib/i386-linux-gnu/libc.so.6

在我的机器上显示

GNU C Library (Ubuntu EGLIBC 2.15-0ubuntu20) stable release version 2.15, by Roland McGrath et al.
Copyright (C) 2012 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 4.6.3 20120918 (prerelease).
Compiled on a Linux 3.5.4 system on 2012-10-04.
Available extensions:
    crypt add-on version 2.1 by Michael Glad and others
    GNU Libidn by Simon Josefsson
    Native POSIX Threads Library by Ulrich Drepper et al
    BIND-8.2.3-T5B
libc ABIs: UNIQUE IFUNC
For bug reporting instructions, please see:
<http://www.debian.org/Bugs/>.

还可以在运行时获取版本信息,使用API gnu_get_libc_version():

#include <stdio.h>
#include <gnu/libc-version.h>
int main()
{
        printf("libc version : %s
", gnu_get_libc_version());
        return 0;
}

运行后显示:

libc version : 2.15
原文地址:https://www.cnblogs.com/jingyg/p/4904665.html