如何查看 glibc 的版本

发布于 2023-02-01 22:24:40 字数 1873 浏览 127 评论 0

找人家排查问题时经常需要说明当前系统是的 glibc 版本。从 https://www.linuxquestions.org/questions/linux-software-2/how-to-check-glibc-version-263103/ 中找到的:

4.9.	How can I find out which version of glibc I am using in the moment?

{UD} If you want to find out about the version from the command line simply
run the libc binary.  This is probably not possible on all platforms but
where it is simply locate the libc DSO and start it as an application.  On
Linux like

  /lib/libc.so.6

This will produce all the information you need.

What always will work is to use the API glibc provides.  Compile and run the
following little program to get the version information:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include <stdio.h>
#include <gnu/libc-version.h>
int main (void) { puts (gnu_get_libc_version ()); return 0; }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This interface can also obviously be used to perform tests at runtime if
this should be necessary.

简单的说就是直接执行

/lib/libc.so.6
GNU C Library (GNU libc) stable release version 2.29.
Copyright (C) 2019 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 8.2.1 20181127.
libc ABIs: UNIQUE IFUNC ABSOLUTE
For bug reporting instructions, please see:
<https://bugs.archlinux.org/>.

但这中方法并不保证一定能用,如果实在不行可以通过 gnu_get_libc_version 函数来获取

#include <stdio.h>
#include <gnu/libc-version.h>
int main (void)
{
  puts (gnu_get_libc_version ());
  return 0;
}
2.29

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

关于作者

Saygoodbye

暂无简介

文章
评论
27 人气
更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文