Find Glibc Version In Your System - OpenGenus IQ
Maybe your like
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 = 31In short, you can find out the glibc version using the following command:
ldd --versionWe 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:
ldd --versionThe 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 <stdio.h> #include <stdlib.h> #include <gnu/libc-version.h> 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:
g++ -std=c++11 glibc.c -o glibcExecute the above code:
./glibcThe output will be:
GNU libc version: 2.31Method 3: gnu_get_libc_version()
In this method, we can identify two versions of glibc:
- Compile time version of glibc
- Runtime version 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 <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 }Compile the above code using the following command:
g++ -std=c++11 glibc.c -o glibcExecute the above code:
./glibcThe output is as follows:
GNU libc compile-time version: 2.31 GNU libc runtime version: 2.31With this, you know how to find out the version of glibc. Happy debugging.
Tag » How To Check Glibc Version
-
How To Get Glibc Version - C Lang
-
Check Glibc Version For A Particular Gcc Compiler - Stack Overflow
-
How To Check Glibc Version?
-
Linux: Check The Glibc Version - Benohead's Software Blog
-
How To Check Glibc Version On Linux - Xmodulo
-
Check Glibc Version In Linux - Lindevs
-
CentOS /RHEL: How To Check GNU Libc Version - OSETC TECH
-
How Do I Tell Which Version Of Glibc I Have Installed On My System?
-
How To Check Glibc Version In Linux - Alfredo's Memo Wiki
-
The GNU C Library
-
How To Check The Glibc Version In Fedora - Liquid Web
-
How To Check The Glibc Version On CentOS - Liquid Web
-
Prints The Various Glibc Versions Required By An Executable · GitHub
-
Check The Actual Glibc Version Used - Unix & Linux Stack Exchange