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 Overflow
🌐
OpenGenus
iq.opengenus.org › find-glibc-version
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.
Discussions

How can I have libstdc++ version and glibc version in profile
The same goes with libstdc++. You can get their versions with: strings /usr/lib/libc.so.6 | grep '^GLIBC_\([0-9.]\)' | sort -u -V | tail -n1 strings /usr/lib/libstdc++.so | grep '^GLIBCXX_\([0-9.]\)' | sort -u -V | tail -n1 More on github.com
🌐 github.com
12
August 30, 2017
How to check glibc version?

ldd --version

More on reddit.com
🌐 r/MXLinux
4
3
September 27, 2022
compiling - Check the actual glibc version used - Unix & Linux Stack Exchange
I want check the glibc version used by toolchain to build code for the target system (ARM). In toolchain directory I tried strings /sysroot/lib/libc.so.6 | grep GLIBC the output is GLIBC_2.4 GL... More on unix.stackexchange.com
🌐 unix.stackexchange.com
August 23, 2019
Is there any simple way to use a different C standard library on macOS?
The C standard library is kind of weird on Unix that it’s more like a part of the operating system, not a part of your toolchain. This is true on Linux, Mac, BSD, Solaris, etc., it’s just that Linux also has a standard kernel interface and that means you can use an alternative standard C library. There’s a lot of detail I’m leaving out here—this is not the full story, and the line between “part of the OS” and “part of your toolchain” is fuzzy. But for now, think of the C standard library as part of your OS, and not something you can choose. Windows is different. On Windows, you bring your own C library and the kernel interface is provided by other libraries. You could just replace printf and bring it from some other library but this would take some work. You could also write your own printf if you wanted. More on reddit.com
🌐 r/C_Programming
10
5
December 5, 2024
Top answer
1 of 6
62

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.
2 of 6
16

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.

🌐
DEV Community
dev.to › bitecode › how-to-get-glibc-version-c-lang-26he
How to get glibc version - C Lang - DEV Community
April 27, 2020 - The easiest way is to use ldd command which comes with glibc and in most cases it will print the same version as glibc:
🌐
Hacker News
news.ycombinator.com › item
Apple doesn't use glibc. | Hacker News
February 17, 2012 - The GCC suite has a pretty clear history of not being dependent on glibc, and some searching brings up no mention of it requiring glibc, and a few mentions of people clearly building it without glibc · http://www-zeuthen.desy.de/linear_collider/cernlib/cernlib_2
🌐
GitHub
github.com › conan-io › conan › issues › 1684
How can I have libstdc++ version and glibc version in profile · Issue #1684 · conan-io/conan
August 30, 2017 - The same goes with libstdc++. You can get their versions with: strings /usr/lib/libc.so.6 | grep '^GLIBC_\([0-9.]\)' | sort -u -V | tail -n1 strings /usr/lib/libstdc++.so | grep '^GLIBCXX_\([0-9.]\)' | sort -u -V | tail -n1
Author   conan-io
🌐
Linux Questions
linuxquestions.org › questions › linux-software-2 › how-to-check-glibc-version-263103
how to check glibc version? - Linux
December 6, 2004 - hi, any method to check glibc version using in my linux box? anyone have idea on this? thanks, jim
Find elsewhere
🌐
Homebrew
formulae.brew.sh › formula › glibc
glibc — Homebrew Formulae
Formula code: glibc.rb on GitHub · Bottle (binary package) installation support provided for: Current versions: Other versions: Keg-only · Depends on: Requires: Brewedglibcnotolder, Linux, Linuxkernel ·
🌐
codestudy
codestudy.net › blog › check-glibc-version-for-a-particular-gcc-compiler
How to Check Glibc Version for a Specific GCC Compiler (Non-Default Installation) — codestudy.net
For glibc, we target libc.so.6 (the shared library). Identify your non-default GCC path: Ensure you’re using the correct GCC. For example, if it’s installed in /opt/gcc-13/bin, use the full path or add it to PATH: # Check GCC version to confirm /opt/gcc-13/bin/gcc --version # Output should show "gcc (GCC) 13.2.0" or similar
🌐
Reddit
reddit.com › r/c_programming › is there any simple way to use a different c standard library on macos?
r/C_Programming on Reddit: Is there any simple way to use a different C standard library on macOS?
December 5, 2024 -

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?

Top answer
1 of 5
8
The C standard library is kind of weird on Unix that it’s more like a part of the operating system, not a part of your toolchain. This is true on Linux, Mac, BSD, Solaris, etc., it’s just that Linux also has a standard kernel interface and that means you can use an alternative standard C library. There’s a lot of detail I’m leaving out here—this is not the full story, and the line between “part of the OS” and “part of your toolchain” is fuzzy. But for now, think of the C standard library as part of your OS, and not something you can choose. Windows is different. On Windows, you bring your own C library and the kernel interface is provided by other libraries. You could just replace printf and bring it from some other library but this would take some work. You could also write your own printf if you wanted.
2 of 5
3
I am aware of no alternative different C standard libraries on mac os, usually it comes with the OS and acts as the formal kernel boundary and API for external users, Linux is really the unusual one with seperate options. Checking apple-clang (gcc is just a wrapper for clang on mac os), closest you can get is using c2x which implemented a relatively recent working draft that did become C23, maybe your feature is there. Otherwise, if the feature you want to use is a language feature and not a library extension or new API, you could actually compile a recent clang version yourself and try that out, I don't know which feature category printf specifiers fall into. But it might just be simpler to use containers or maybe a VM in your favorite IDE as the compile environment and use a recent clang/gcc/glibc there.
🌐
GitHub
github.com › pkgxdev › setup › issues › 39
check macOS version (& glibc?) · Issue #39 · pkgxdev/setup
October 4, 2022 - We require macOS 11. strictly we require a glibc version at this point too, but we’d like to switch to depending on musl and should try to do this before we launch (if possible)
Author   pkgxdev
🌐
GitHub
github.com › NixOS › nixpkgs › issues › 103356
glibc fails to build on macOS · Issue #103356 · NixOS/nixpkgs
November 10, 2020 - 1 out of 1 hunk ignored builder for '/nix/store/wnq9m218wjbk418m2b8gsng1s8kamacn-glibc-2.32.drv' failed with exit code 1 error: build of '/nix/store/wnq9m218wjbk418m2b8gsng1s8kamacn-glibc-2.32.drv' failed ... Metadata Please run nix-shell -p nix-info --run "nix-info -m" and paste the result. - system: `"x86_64-darwin"` - host os: `Darwin 19.6.0, macOS 10.15.7` - multi-user?: `no` - sandbox: `no` - version: `nix-env (Nix) 2.3.8` - channels(crestani): `"nixpkgs-19.03pre153206.f753852e11d"` - nixpkgs: `/Users/crestani/nixpkgs`
Author   NixOS
🌐
Gordano
gordano.com › home › knowledge base › gms › how do i tell which version of glibc i have installed on my system?
How do I tell which version of glibc I have installed on my system? – GMS
To determine which to download and install on Redhat RPM based systems, please open a command prompt on your Linux server and type "rpm -q glibc" then press the Enter key. The version of glibc you are running will be returned on the command line.
🌐
N-able
documentation.n-able.com › remote-management › userguide › Content › linux_v2_dependencies.htm
Package Dependencies
To view whether glibc is installed on the server and its version number run the ldd command with the version switch. ... Where glibc is not discovered on the device, the following command installs the package. This requires root to install. ... To check whether the computer is using DNF or ...