ldd --version
你没有看错,libc.so是一个可执行程序。
但前提是你要找到它。因为它并不在PATH所包含的目录下。
pp@dell:~$ ldd `which cat` | grep libc
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f0e6fb34000)
pp@dell:~$ /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>.
main.c
用代码还分了3种方式:
#include <gnu/libc-version.h>
#include <stdio.h>
#include <unistd.h>
int main() {
// method 1, use macro
printf("%d.%d\n", __GLIBC__, __GLIBC_MINOR__);
// method 2, use gnu_get_libc_version
puts(gnu_get_libc_version());
// method 3, use confstr function
char version[30] = {0};
confstr(_CS_GNU_LIBC_VERSION, version, 30);
puts(version);
return 0;
}
$ gcc main.c -o main
$ ./main
2.30
2.30
glibc 2.30