glibc的版本确认

运行环境为 Ubuntu 22.04

查看系统中安装的libc的软件包

1
2
$ dpkg -l |grep -i libc-bin
ii libc-bin 2.35-0ubuntu3.1 amd64 GNU C Library: Binaries

采用gnu的接口查询

可以通过man gnu_get_libc_version查看接口的详细信息

1
2
3
4
5
6
7
8
9
10
11
12
13
$ cat 003_glibc_verison.c -n
1 #include <stdio.h>
2 #include <gnu/libc-version.h>
3
4 void main() {
5 printf("GNU C library version: %s\n", gnu_get_libc_version());
6 printf("GNU C library release: %s\n", gnu_get_libc_release());
7 }
$ gcc 003_glibc_verison.c
$ ./a.out
GNU C library version: 2.35
GNU C library release: stable
$

ldd命令

1
2
3
4
5
6
7
$ ldd --version
ldd (Ubuntu GLIBC 2.35-0ubuntu3.1) 2.35
Copyright (C) 2022 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.
$

执行libc.so

libc.so是可以直接运行的,如果不能运行,chmod +x添加下执行权限
ldd 一个当前系统中 C 库编写的动态可执行程序,可以查找到使用的libc.so的位置

1
2
3
4
5
6
7
8
9
10
11
12
13
$ ldd `which top`|grep -i libc.so
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f3a024b2000)
$ /lib/x86_64-linux-gnu/libc.so.6
GNU C Library (Ubuntu GLIBC 2.35-0ubuntu3.1) stable release version 2.35.
Copyright (C) 2022 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 11.2.0.
libc ABIs: UNIQUE IFUNC ABSOLUTE
For bug reporting instructions, please see:
<https://bugs.launchpad.net/ubuntu/+source/glibc/+bugs>.
$