$ ldd --version
ldd (GNU libc) 2.17
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
... 这与运行我的libc库的结果相同
$ /lib/libc.so.6
GNU C Library (GNU libc) stable release version 2.17, by Roland McGrath et al.
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
$ file $(gcc -print-file-name=libc.so)
/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libc.so: ASCII text
$ cat $(gcc -print-file-name=libc.so)
/* GNU ld script
Use the shared library, but some functions are only in
the static library, so try that secondarily. */
OUTPUT_FORMAT(elf64-x86-64)
GROUP ( /lib/x86_64-linux-gnu/libc.so.6 /usr/lib/x86_64-linux-gnu/libc_nonshared.a AS_NEEDED ( /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 ) )
$ file /lib/x86_64-linux-gnu/libc.so.6
/lib/x86_64-linux-gnu/libc.so.6: symbolic link to libc-2.31.so
$ file $(readlink -f /lib/x86_64-linux-gnu/libc.so.6)
/usr/lib/x86_64-linux-gnu/libc-2.31.so: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=1878e6b475720c7c51969e69ab2d276fae6d1dee, for GNU/Linux 3.2.0, stripped
$ /lib/x86_64-linux-gnu/libc.so.6
GNU C Library (Ubuntu GLIBC 2.31-0ubuntu9.9) stable release version 2.31.
Copyright (C) 2020 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 9.4.0.
libc ABIs: UNIQUE IFUNC ABSOLUTE
For bug reporting instructions, please see:
<https://bugs.launchpad.net/ubuntu/+source/glibc/+bugs>.
dina@dina-X450LA:~$ ldd --version
ldd (Ubuntu GLIBC 2.23-0ubuntu9) 2.23
Copyright (C) 2016 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.
还有另外两种方法可以找到glibc版本: 1.检查已安装的glibc rpm软件包的版本:通过运行以下命令 rpm -q glibc 1.检查所用的www.example.com文件的版本libc.so。这种方法稍微困难一点。您可以在以下链接中检查:Linux: Check the glibc version
8条答案
按热度按时间d5vmydt91#
此外,请检查libc得更高版本符号:
xytpbqjk2#
更容易
使用
ldd --version
这将返回正在使用的glibc版本,即
...
这与运行我的libc库的结果相同
...
cs7cruho3#
编写一个测试程序(例如命名为
glibc-version.c
):并使用gcc-4.4编译器对其进行编译:
当您执行
./glibc-version
时,会显示使用的glibc版本。tgabmvqs4#
使用
-print-file-name
gcc
选项:这给出了路径。让我们检查文件:
该文件是一个链接器脚本,用于链接
GROUP
列表中的库。在ELF平台上,
/lib/x86_64-linux-gnu/libc.so.6
是一个与位置无关的可执行文件,带有一个动态符号表(类似于共享库的符号表):kxkpmulp5#
gnu_get_libc_version
标识GNU C库的 * 运行时 * 版本。如果你关心的是 * 编译时 * 版本(也就是在
/usr/include
中提供头文件的版本),你应该看看宏__GLIBC__
和__GLIBC_MINOR__
。它们扩展为正整数,并且将被定义为包含 * GNU C库提供的 * 任何 * 头文件的副作用;这意味着您可以包含一个标准的头文件,然后使用#ifdef __GLIBC__
来决定是否可以包含一个非标准的头文件,如gnu/libc-version.h
。从已接受的答案扩展测试程序:
当我编译并运行这个程序时,我在电脑上输入这个答案(这是一个Mac),它打印
但当在附近的Linux机器上编译和运行时,它会打印
在正常情况下,“运行时”版本可能比“编译时”版本大,但绝不会小。主版本号不太可能再改变(上一次改变是在1997年的“libc 6过渡”)。
如果您希望使用shell“一行程序”来转储这些宏,请用途:
选择
grep
模式是为了只匹配两个相关的宏,因为有许多名为__GLIBC_somethingorother
的内部宏,您不希望必须通读它们。hgc7kmma6#
我怀疑你的系统中是否安装了不止一个glibc。但是
ldd -v <path/to/gcc-4.x>
应该会给予你使用的glibc。u4dcyp6a7#
最简单的方法是使用
glibc
附带的ldd
只需运行以下命令
ldd --version
:还有另外两种方法可以找到glibc版本:
1.检查已安装的glibc rpm软件包的版本:通过运行以下命令
rpm -q glibc
1.检查所用的www.example.com文件的版本libc.so。这种方法稍微困难一点。您可以在以下链接中检查:Linux: Check the glibc version
klh5stk18#
您可以使用字符串命令来检查编译器的GLIBC版本。最高版本适用。