GUN C 语言函数库是 Linux 上最常用的库 (glibc) http://www.gnu.org/
应用程序可以通过测试常量和调用库函数两种方法,来确定系统安装的glibc版本,从2.0开始,glibc提供两个常量
__GLIBC__ 和 __GLIBC_MINOR__
一、程序获取glibc 版本号
// gunc_lib_version.c
#include<stdio.h>
#include<gnu/libc-version.h>
int main(void)
{
char * str_gnu_ver = gnu_get_libc_version();
printf("gnu lib version : %s \n",str_gnu_ver);
printf("__GLIBC__ = %d \n",__GLIBC__);
printf("__GLIBC_MINOR__ = %d \n",__GLIBC_MINOR__);
return 0 ;
}
~
编译运行: gcc gunc_lib_version.c -o gunc_lib_version
yexiang@ubuntu:<Linux_work>$ ./gunc_lib_version
gnu lib version : 2.23
__GLIBC__ = 2
__GLIBC_MINOR__ = 23
二、查看程序连接的glibc库
yexiang@ubuntu:<Linux_work>$ ldd gunc_lib_version | grep libc
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f0d165ac000)
yexiang@ubuntu:<Linux_work>$ /lib/x86_64-linux-gnu/libc.so.6
GNU C Library (Ubuntu GLIBC 2.23-0ubuntu11) stable release version 2.23, by Roland McGrath et al.
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.
Compiled by GNU CC version 5.4.0 20160609.
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:
<https://bugs.launchpad.net/ubuntu/+source/glibc/+bugs>.