Linux get glibc version

Check glibc version for a particular gcc compiler

I have two gcc compilers installed on my system, one is gcc 4.1.2 (default) and the other is gcc 4.4.4 . How can I check the libc version used by gcc 4.4.4 , because /lib/libc.so.6 shows the glibc used by gcc 4.1.2 , since it is the default compiler.

If you want to perform the check at compile time, then Zwol’s answer below is probably the best method. If you want to check the version at runtime, then R1tschY’s answer is probably the best method. Note that you may not get the Glibc version or standard C++ library version you expect at runtime due to Linux’s inability to get the paths right on its own. Also see Linking g++ 4.8 to libstdc++

9 Answers 9

This should return the glibc version being used i.e.

$ ldd --version ldd (GNU libc) 2.17 Copyright (C) 2012 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO 

which is the same result as running my libc library

$ /lib/libc.so.6 GNU C Library (GNU libc) stable release version 2.17, by Roland McGrath et al. Copyright (C) 2012 Free Software Foundation, Inc. This is free software; see the source for copying conditions. 

Results from above commands are not the same. On my computer : GNU libc version: 2.17, ld-linux-x86-64.so.2 (GLIBC_2.3) => /lib64/ld-linux-x86-64.so.2 ??

That shows what ldd was linked with. When linking programs you link with some implementation of libc (there can be more than one), not with ldd .

Write a test program (name it for example glibc-version.c ):

#include #include #include int main(int argc, char *argv[])

and compile it with the gcc-4.4 compiler:

gcc-4.4 glibc-version.c -o glibc-version 

When you execute ./glibc-version the used glibc version is shown.

it works for me, but where is this docummented? I’m looking at the glibc 2.7 docs but I can’t find it.

I use OSX and I am getting ==> fatal error: ‘gnu/libc-version.h’ file not found

OSX has never used the GNU C Library; its Unix userspace is all BSD-derived. It did originally use GCC as its system compiler, but Apple as an organization is allergic to the GPLv3; it is not an accident that they started funding LLVM heavily right after GCC’s licensing was changed over.

Use -print-file-name gcc option:

$ gcc -print-file-name=libc.so /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libc.so 

That gives the path. Let’s examine the file:

$ file $(gcc -print-file-name=libc.so) /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libc.so: ASCII text $ cat $(gcc -print-file-name=libc.so) /* GNU ld script Use the shared library, but some functions are only in the static library, so try that secondarily. */ OUTPUT_FORMAT(elf64-x86-64) GROUP ( /lib/x86_64-linux-gnu/libc.so.6 /usr/lib/x86_64-linux-gnu/libc_nonshared.a AS_NEEDED ( /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 ) ) 

The file is a linker script, which links the libraries in GROUP list.

Читайте также:  Linux amd какие драйвера лучше

On ELF platforms /lib/x86_64-linux-gnu/libc.so.6 is a position-independent executable with a dynamic symbol table (like that of a shared library):

$ file /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/libc.so.6: symbolic link to libc-2.31.so $ file $(readlink -f /lib/x86_64-linux-gnu/libc.so.6) /usr/lib/x86_64-linux-gnu/libc-2.31.so: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=1878e6b475720c7c51969e69ab2d276fae6d1dee, for GNU/Linux 3.2.0, stripped $ /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: . 

Источник

Linux: Check the glibc version

If you need to check which version of the GNU C library (glibc) is used on you Linux system, whether it’s to check whether you are affected by the GHOST vulnerability or you need to install a software requiring at least a certain version but not checking it on build/installation, the easiest way is to use ldd which comes with glibc and should in most cases have the same version:

> ldd --version ldd (GNU libc) 2.11.1

If you know you might have patched the system to use a different version of ldd and know that its version doesn’t match the glibc version, you have two additional ways to find out the glibc version:

  1. Check the version of the installed glibc rpm package
  2. Check the version of the used libc.so file
> rpm -q glibc glibc-2.11.1-0.17.4

The second way is a little bit more difficult. You first have to find which libc.so file is being used by a known program e.g. netstat:

> ldd `which netstat` linux-vdso.so.1 => (0x00007ffff7ffb000) libc.so.6 => /lib64/libc.so.6 (0x00007ffff7a80000) /lib64/ld-linux-x86-64.so.2 (0x00007ffff7dde000)

You can also find the libc.so file used with the following command:

> cat `gcc -print-file-name=libc.so` /* GNU ld script Use the shared library, but some functions are only in the static library, so try that secondarily. */ OUTPUT_FORMAT(elf64-x86-64) GROUP ( /lib64/libc.so.6 /usr/lib64/libc_nonshared.a AS_NEEDED ( /lib64/ld-linux-x86-64.so.2 ) )

So we now know that /lib64/libc.so.6 is being used and we just need to get it’s version:

> /lib64/libc.so.6 --version GNU C Library stable release version 2.11.1 (20100118), by Roland McGrath et al. Copyright (C) 2009 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. Configured for x86_64-suse-linux. Compiled by GNU CC version 4.3.4 [gcc-4_3-branch revision 152973]. Compiled on a Linux 2.6.32 system on 2010-05-06. 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 For bug reporting instructions, please see: .

If you want to determine the glibc version from C program and not from a shell script, you can just use something like this:

#include #include #include int main(int argc, char *argv[])

You can then compile it and execute it like this to get the glibc version:

> gcc glibc_version.c -o glibc_version > ./glibc_version glibc version: 2.11.1

Of course, if your C file is not called glibc_version.c, you’ll have to use the name you’ve actually used in the gcc arguments.

Читайте также:  Microsoft office linux 2007

Since your current shell is probably also using glibc, you can also find out which libc library it has loaded by using the following command:

> lsof -p $$ | grep libc bash 9177 root mem REG 8,2 1661454 827401 /lib64/libc-2.11.1.so

Of course there may be systems where the file name itself doesn’t give you the glibc version but just as shown above with /lib64/libc.so.6 you can call the so file with the –version to get its version information e.g.:

lsof -p $$ | grep libc | awk ' < print $NF" --version"; >' | sh GNU C Library stable release version 2.11.1 (20100118), by Roland McGrath et al. Copyright (C) 2009 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. Configured for x86_64-suse-linux. Compiled by GNU CC version 4.3.4 [gcc-4_3-branch revision 152973]. Compiled on a Linux 2.6.32 system on 2010-05-06. 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 For bug reporting instructions, please see: .

Источник

How to check glibc version on Linux

Question: I need to find out the version of the GNU C library ( glibc ) that I have on my Linux system. How can I check glibc version on Linux?

The GNU C library ( glibc ) is the GNU implementation of the standard C library. glibc is a critical component of the GNU toolchain, which is used along with binutils and compiler to generate userspace application binaries for a target architecture.

When built from source, some Linux programs may be required to link against a particular version of glibc . In that case, you may want to check out the information about installed glibc to see if dependencies are met.

Here are simple ways to check glibc version on Linux.

Method One

A simple command-line to check the version of the GNU C library is as follows.

In this example, the version of glibc is 2.19.

Method Two

Another method is to «type» the glibc library (i.e., libc.so.6 ) from the command line as if it were a command.

The output will show more detailed information about glibc library, including the version of glibc and the GNU compiler used, as well as available glibc extensions. The location of glibc varies depending on distros and processor architectures.

On 64-bit Debian based system:

on 32-bit Debian based system:

On 64-bit Red Hat based system:

On 32-bit Red Hat based systems:

Here is the sample output of typing glibc library.

Читайте также:  Gtx 560 ti linux driver

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

Источник

Find glibc version in your system

In this guide at OpenGenus, we present 3 different ways to identify compile time and run time version of glibc. The version of glibc has two components: Major version and Minor version. It is as follows:

glibc version glibc MAJOR_VERSION.MINOR_VERSION glibc 2.31 MAJOR_VERSION = 2 MINOR_VERSION = 31 

In short, you can find out the glibc version using the following command:

We find the glibc version using the following ways:

  • Method 1: Use ldd
  • Method 2: Use libc-version.h in C++ code
  • Method 3: gnu_get_libc_version()

glibc is GNU C Library which provides the Standard C implementation and also, supports C++. It provides the core libraries in Linux kernel and hence, is used in every operating system that uses Linux as the kernel like RHEL, CentOS, Ubuntu and many others.

For a certain software, the glibc version should be the same in the destination system as in the origin system where the software has been compiled. You may have faced glibc errors and hence, need to find out the glibc version you are using.

Following are the methods:

Method 1: Use ldd

Use the following command in the terminal:

The output will give the version of glibc used:

ldd (Ubuntu GLIBC 2.31-0ubuntu9.2) 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. Written by Roland McGrath and Ulrich Drepper. 

Method 2: Use libc-version.h in C++ code

Add the following C++ code in a file named «glibc.cpp»:

// Part of iq.OpenGenus.org #include #include #include int main(int argc, char *argv[]) < // Print glibc version printf("GNU libc version: %s\n", gnu_get_libc_version()); exit(EXIT_SUCCESS); >

Compile the above code using the following command:

Method 3: gnu_get_libc_version()

In this method, we can identify two versions of glibc:

The compile time version of glibc is defined in macros __GLIBC__ and __GLIBC_MINOR__ .

The run time version of glibc is available using the function gnu_get_libc_version().

Note that the run time version of glibc can be greater than the compile time version of glibc but never smaller. The major version is likely to be the same.

Add the following code in a file named «glibc.c»:

// Part of iq.OpenGenus.org #include #ifdef __GLIBC__ #include #endif int main(void)

Compile the above code using the following command:

GNU libc compile-time version: 2.31 GNU libc runtime version: 2.31 

With this, you know how to find out the version of glibc. Happy debugging.

Источник

Оцените статью
Adblock
detector