Use ldd --version:
Copy$ 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
...
You can also run libc itself:
Copy$ /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.
...
Answer from John on Stack OverflowUse ldd --version:
Copy$ 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
...
You can also run libc itself:
Copy$ /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.
...
Write a test program (name it for example glibc-version.c):
Copy#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:
Copygcc-4.4 glibc-version.c -o glibc-version
When you execute ./glibc-version the used glibc version is shown.
How can I have libstdc++ version and glibc version in profile
How to check glibc version?
ldd --version
More on reddit.comcompiling - Check the actual glibc version used - Unix & Linux Stack Exchange
Is there any simple way to use a different C standard library on macOS?
GNU/Linux systems usually use either glibc (Fedora/Redhat family, Arch) or its close cousin, eglibc (Debian/Ubuntu family); since eglibc is now being merged back into glibc (see EGLIBC 2.19 Branch Created under "News"), in the near future they will all be glibc again.
The easiest way to check the exact version is to ask ldd, which ships with the C library.
On Fedora 20:
> ldd --version
ldd (GNU libc) 2.18
That's glibc 2.18.
On Raspbian (Debian 7 port for ARMv6 Broadcom SoC):
> ldd --version
ldd (Debian EGLIBC 2.13-38+rpi2) 2.13
That's eglibc 2.13.
If for whatever reason you have mixed and matched some parts or otherwise aren't sure about ldd, you can query the C library directly.
> whereis libc.so
libc: /usr/lib64/libc.a /usr/lib64/libc.so /usr/share/man/man7/libc.7.gz
None of those is executable but they provide a clue about where to find one.
> $(find /usr/lib64/ -executable -name "*libc.so*") --version
GNU C Library (GNU libc) stable release version 2.18, by Roland McGrath et al.
However, it is not necessarily so easy, because the C library does not have to reside somewhere whereis can find it.
> whereis libc.so
libc: /usr/share/man/man7/libc.7.gz
Unfortunately, the man page does not provide a version number. ldd still comes in handy, since any working, dynamically linked executable on the system (e.g., almost everything in /usr/bin) will link to the C library.
> ldd /usr/bin/touch
/usr/lib/arm-linux-gnueabihf/libcofi_rpi.so (0xb6eed000)
librt.so.1 => /lib/arm-linux-gnueabihf/librt.so.1 (0xb6ed0000)
libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0xb6da1000)
/lib/ld-linux-armhf.so.3 (0xb6efb000)
libpthread.so.0 => /lib/arm-linux-gnueabihf/libpthread.so.0 (0xb6d82000)
libc.so.6 is on the third line.
> /lib/arm-linux-gnueabihf/libc.so.6 --version
GNU C Library (Debian EGLIBC 2.13-38+rpi2) stable release version 2.13, by Roland McGrath et al.
A system isn't actually limited to one C library. Most, though, primarily use only one, which will also be the one the default compiler uses. And since you're downloading source code to compile, that's the one you're concerned with.
Start with a trivial program:
#include <stdio.h>
int main() {
printf("Hello, world\n");
return 0;
}
compile it using the compiler you're going to use for the source code, then use ldd to find out where the C library is:
$ ldd ./libc-test
linux-vdso.so.1 (0x00007fff2e5fe000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f8c8ad98000)
/lib64/ld-linux-x86-64.so.2 (0x00007f8c8b171000)
You now have the path to the C library. You could look this up in your package manager to find the package (e.g., dpkg -S /lib/x86_64-linux-gnu/libc.so.6 or rpm -q -f /lib/x86_64-linux-gnu/libc.so.6).
At least in the case of eglibc/glibc, you can run it:
$ /lib/x86_64-linux-gnu/libc.so.6
GNU C Library (Debian EGLIBC 2.18-4) stable release version 2.18, by Roland McGrath et al.
Copyright (C) 2013 Free Software Foundation, Inc.
⋮
Finally, you could see if you can get clues from objdump -p /lib/x86_64-linux-gnu/libc.so.6, by looking in the version definitions section:
Version definitions:
1 0x01 0x0865f4e6 libc.so.6
2 0x00 0x09691a75 GLIBC_2.2.5
3 0x00 0x09691a76 GLIBC_2.2.6
⋮
21 0x00 0x06969197 GLIBC_2.17
GLIBC_2.16
22 0x00 0x06969198 GLIBC_2.18
GLIBC_2.17
23 0x00 0x0963cf85 GLIBC_PRIVATE
GLIBC_2.18
Note how the GLIBC_2.18 symbol has the most recent version number among the symbols listed, and the library version is indeed 2.18. It's eglibc, though (it aims to be binary-compatible with glibc 2.18, so it uses the same symbol versions).
You could also attempt to use strings to find out something about it. You'll want to specify a longer minimal length (-n), or use grep to search for something:
$ strings /lib/x86_64-linux-gnu/libc.so.6 | grep 'version [0-9]'
$ strings /lib/x86_64-linux-gnu/libc.so.6 | grep -iC1 'copyright'
both work for this eglibc.
NOTE: The Debian package utility dpkg-shlibdeps uses objdump under the hood, along with stored symbol information in Debian library packages to determine the minimum versions of dependencies required by binary Debian packages at build time. Basically, it looks at the symbols exported by the binary Debian package, and then finds the minimum versions of the libraries that contain those symbols.
How to check what glibc version i have installed? If i run dpkg -l | grep glibc i don't get any output. I am using MX-21.2.1_x64 Wildflower.
I wanted to try out some C23 features, for example the new %b and %B format specifiers for printf and friends.
The C standard library on macOS is an older version which doesn't support the newer standard, so I tried to find out whether there's a updated version that I could use. But I couldn't find anything that works on macOS!
LLVM has libc++, but that's for C++. glibc doesn't appear to work on macOS. LLVM has a project called llvm-libc, but that's work-in-progress.
Are there any alternatives that are as simple as just installing something?
For glibc:
/lib/libc.so.6
Sounds maybe strange to run a so file but should print out version information in this case
For the kernel version use uname
For the binutils parsing the output of ld --versionmight yield what you expect, the same for gcc --version. This is a bit tedious but I do not know another way.
$ ldd --version
ldd (GNU libc) 2.39