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.

- 29,191
- 52
- 200
- 356
-
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++](https://stackoverflow.com/q/17220872/608639) – jww Jul 14 '17 at 16:51
9 Answers
even easier
use ldd --version
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.
...

- 36,492
- 15
- 194
- 265

- 719
- 6
- 7
-
4Results 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 ?? – Adam Apr 26 '14 at 09:53
-
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`. – Maxim Egorushkin Aug 09 '22 at 16:50
Write a test program (name it for example glibc-version.c
):
#include <stdio.h>
#include <stdlib.h>
#include <gnu/libc-version.h>
int main(int argc, char *argv[]) {
printf("GNU libc version: %s\n", gnu_get_libc_version());
exit(EXIT_SUCCESS);
}
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.

- 3,032
- 1
- 24
- 30
-
it works for me, but where is this docummented? I'm looking [at the glibc 2.7 docs](http://www.gnu.org/software/libc/manual/html_mono/libc.html) but I can't find it. – Ciro Santilli OurBigBook.com Jun 27 '13 at 09:58
-
The function is part of the Gnulib: https://www.gnu.org/software/gnulib/manual/gnulib.html – R1tschY Jul 09 '13 at 09:29
-
7
-
I use OSX and I am getting ==> fatal error: 'gnu/libc-version.h' file not found <== Why might this be? Does not osx come with standard c library? – Koray Tugay Jun 11 '15 at 10:32
-
@KorayTugay: Well, yes, but OS X/macOS started switching over from GCC to LLVM/Clang (though it _did_ have an instance of LLVM-GCC available for a little while) all the way back with the release of Xcode 3.1, IIRC, so you'd have to look for _Clang's_ C standard library. – RandomDSdevel May 14 '17 at 19:48
-
4OSX 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. – zwol Feb 20 '18 at 14:34
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.
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:
<https://bugs.launchpad.net/ubuntu/+source/glibc/+bugs>.

- 131,725
- 17
- 180
- 271
gnu_get_libc_version
identifies the runtime version of the GNU C Library.
If what you care about is the compile-time version (that is, the version that provided the headers in /usr/include
), you should look at the macros __GLIBC__
and __GLIBC_MINOR__
. These expand to positive integers, and will be defined as a side-effect of including any header file provided by the GNU C Library; this means you can include a standard header, and then use #ifdef __GLIBC__
to decide whether you can include a nonstandard header like gnu/libc-version.h
.
Expanding the test program from the accepted answer:
#include <stdio.h>
#ifdef __GLIBC__
#include <gnu/libc-version.h>
#endif
int
main(void)
{
#ifdef __GLIBC__
printf("GNU libc compile-time version: %u.%u\n", __GLIBC__, __GLIBC_MINOR__);
printf("GNU libc runtime version: %s\n", gnu_get_libc_version());
return 0;
#else
puts("Not the GNU C Library");
return 1;
#endif
}
When I compile and run this program on the computer I'm typing this answer on (which is a Mac) it prints
Not the GNU C Library
but when compiled and run on a nearby Linux box it prints
GNU libc compile-time version: 2.24
GNU libc runtime version: 2.24
Under normal circumstances, the "runtime" version could be bigger than the "compile-time" version, but never smaller. The major version number is unlikely ever to change again (the last time it changed was the "libc6 transition" in 1997).
If you would prefer a shell 'one-liner' to dump these macros, use:
echo '#include <errno.h>' | gcc -xc - -E -dM |
grep -E '^#define __GLIBC(|_MINOR)__ ' | sort
The grep
pattern is chosen to match only the two macros that are relevant, because there are dozens of internal macros named __GLIBC_somethingorother
that you don't want to have to read through.

- 135,547
- 38
- 252
- 361
-
And from comments on a related question: `echo '#include
' | gcc -x c -dM -E - | egrep -i '(gnu|lib)'`. – jww Jul 14 '17 at 16:47 -
Uclibc-ng supports `gnu_get_libc_version()`, so "Not the GNU C Library" is not precise. – pevik Aug 13 '18 at 12:19
-
-
@zwol Yes, it does: in [features.h](https://cgit.openadk.org/cgi/cgit/uclibc-ng.git/tree/include/features.h#n82), which is used in [gnu/libc-version.h](https://cgit.openadk.org/cgi/cgit/uclibc-ng.git/tree/include/gnu/libc-version.h). – pevik Aug 14 '18 at 06:19
-
@pevik I would say that's a bug in uclibc, unless it _already_ supports every single glibc extension, which seems unlikely. – zwol Aug 14 '18 at 13:12
-
@zwol IMHO it's not. They define `__GLIBC__ 2` and `__GLIBC_MINOR__ 2` in [features.h](https://cgit.openadk.org/cgi/cgit/uclibc-ng.git/tree/include/features.h#n387), which is what they probably fully support. glibc 2.2 was released 2000-11-09 (18 years ago) and if you compare headers from both projects, they look similar. – pevik Aug 14 '18 at 17:41
-
@zwol see also https://blogs.gentoo.org/blueness/2016/03/31/why-macros-like-__glibc__-and-__uclibc__-are-bad/ – pevik Aug 14 '18 at 17:53
I doubt if you have more than one glibc installed in your system.But ldd -v <path/to/gcc-4.x>
should give you the glibc used.

- 3,406
- 3
- 23
- 30
-
1`-v` was killer advice in my case and helped me see exactly what library versions were missing. – Artem Russakovskii Jun 13 '23 at 06:56
The easiest way is to use ldd
which comes with glibc
Just run this command ldd --version
:
dina@dina-X450LA:~$ ldd --version
ldd (Ubuntu GLIBC 2.23-0ubuntu9) 2.23
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.
Written by Roland McGrath and Ulrich Drepper.
Their is two additional ways to find out the glibc version:
Check the version of the installed glibc rpm package : this by runing this command
rpm -q glibc
Check the version of the used libc.so file. This way is a little bit more difficult. You can check it in this link: Linux: Check the glibc version

- 7,074
- 10
- 69
- 74
You can use strings command to check GLIBC version of compiler. Highest version is applicable.
ubuntu1604:extra$ strings ./arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-gcc | grep GLIBC
GLIBC_2.3
GLIBC_2.8
GLIBC_2.14
GLIBC_2.4
GLIBC_2.11
GLIBC_2.2.5
GLIBC_2.3.4

- 836
- 1
- 10
- 29
-
3Note that this does not really tell you the version. Let's assume that the binary was linked against glibc 2.17, but happened not to reference any symbols with symbol versions later than `GLIBC_2.14`. Then it could easily produce the same list of symbol versions. – Florian Weimer Jul 17 '17 at 11:05
At first do
ldd
which cat | grep libc
to find
libc.so.6
If output be for example
/lib/x86_64-linux-gnu/libc.so.6
Then run that, which output result will be
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:
<https://bugs.launchpad.net/ubuntu/+source/glibc/+bugs>.

- 637
- 2
- 9
- 22