Skip to content

Latest commit

 

History

History
67 lines (55 loc) · 2.11 KB

如何查看glibc的版本.org

File metadata and controls

67 lines (55 loc) · 2.11 KB

如何查看glibc的版本

找人家排查问题时经常需要说明当前系统是的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_get_libc_version 函数来获取

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