- How do you find what version of libstdc++ library is installed on your linux machine?
- 4 Answers 4
- Checking a Library Version in Linux
- 1. Overview
- 2. Using the dpkg Command
- 2.1. Using dpkg
- 2.2. Using dpkg With grep
- 2.3. Using dpkg-query
- 3. Using the apt Command
- 4. Conclusion
- Find out library version
- 4 Answers 4
- You must log in to answer this question.
- Related
- Hot Network Questions
- Subscribe to RSS
How do you find what version of libstdc++ library is installed on your linux machine?
I found the following command: strings /usr/lib/libstdc++.so.6 | grep GLIBC from here. It seems to work but this is an ad-hoc/heuristic method. Is there a specific command that can be used to query the library version of C++? Or is the method I found the accepted method?
4 Answers 4
To find which library is being used you could run
$ /sbin/ldconfig -p | grep stdc++ libstdc++.so.6 (libc6) => /usr/lib/libstdc++.so.6
The list of compatible versions for libstdc++ version 3.4.0 and above is provided by
$ strings /usr/lib/libstdc++.so.6 | grep LIBCXX GLIBCXX_3.4 GLIBCXX_3.4.1 GLIBCXX_3.4.2 .
For earlier versions the symbol GLIBCPP is defined.
The date stamp of the library is defined in a macro __GLIBCXX__ or __GLIBCPP__ depending on the version:
// libdatestamp.cxx #include int main(int argc, char* argv[]) < #ifdef __GLIBCPP__ std::printf("GLIBCPP: %d\n",__GLIBCPP__); #endif #ifdef __GLIBCXX__ std::printf("GLIBCXX: %d\n",__GLIBCXX__); #endif return 0; >$ g++ libdatestamp.cxx -o libdatestamp $ ./libdatestamp GLIBCXX: 20101208
The table of datestamps of libstdc++ versions is listed in the documentation:
The datestamps are almost entirely useless, I don’t know why we bother keeping them or documenting them. For example, the date for GCC 4.6.3 is later than 4.7.0, but 4.7.0 has more features, so what use is knowing the date it was released?
It can be short form to strings $(/sbin/ldconfig -p | grep stdc++|awk -F’=>’ ‘
What exactly do you want to know?
The shared library soname? That’s part of the filename, libstdc++.so.6 , or shown by readelf -d /usr/lib64/libstdc++.so.6 | grep soname .
The minor revision number? You should be able to get that by simply checking what the symlink points to:
$ ls -l /usr/lib/libstdc++.so.6 lrwxrwxrwx. 1 root root 19 Mar 23 09:43 /usr/lib/libstdc++.so.6 -> libstdc++.so.6.0.16
That tells you it’s 6.0.16, which is the 16th revision of the libstdc++.so.6 version, which corresponds to the GLIBCXX_3.4.16 symbol versions.
Or do you mean the release it comes from? It’s part of GCC so it’s the same version as GCC, so unless you’ve screwed up your system by installing unmatched versions of g++ and libstdc++.so you can get that from:
Or, on most distros, you can just ask the package manager. On my Fedora host that’s
$ rpm -q libstdc++ libstdc++-4.6.3-2.fc16.x86_64 libstdc++-4.6.3-2.fc16.i686
As other answers have said, you can map releases to library versions by checking the ABI docs
«ask the package manager» is a good approach. On Debian 9 I run apt list libstdc++6 and get libstdc++6/oldoldstable,oldoldstable,now 6.3.0-18+deb9u1 amd64 [installed]
The mechanism I tend to use is a combination of readelf -V to dump the .gnu.version information from libstdc++, and then a lookup table that matches the largest GLIBCXX_ value extracted.
readelf -sV /usr/lib/libstdc++.so.6 | sed -n 's/.*@@GLIBCXX_//p' | sort -u -V | tail -1
if your version of sort is too old to have the -V option (which sorts by version number) then you can use:
tr '.' ' ' | sort -nu -t ' ' -k 1 -k 2 -k 3 -k 4 | tr ' ' '.'
instead of the sort -u -V , to sort by up to 4 version digits.
In general, matching the ABI version should be good enough.
If you’re trying to track down the libstdc++.so. , though, you can use a little bash like:
file=/usr/lib/libstdc++.so.6 while [ -h $file ]; do file=$(ls -l $file | sed -n 's/.*-> //p'); done echo $
so for my system this yielded 6.0.10 .
If, however, you’re trying to get a binary that was compiled on systemX to work on systemY, then these sorts of things will only get you so far. In those cases, carrying along a copy of the libstdc++.so that was used for the application, and then having a run script that does an:
export LD_LIBRARY_PATH= exec application.bin "$@"
generally works around the issue of the .so that is on the box being incompatible with the version from the application. For more extreme differences in environment, I tend to just add all the dependent libraries until the application works properly. This is the linux equivalent of working around what, for windows, would be considered dll hell.
Checking a Library Version in Linux
The Kubernetes ecosystem is huge and quite complex, so it’s easy to forget about costs when trying out all of the exciting tools.
To avoid overspending on your Kubernetes cluster, definitely have a look at the free K8s cost monitoring tool from the automation platform CAST AI. You can view your costs in real time, allocate them, calculate burn rates for projects, spot anomalies or spikes, and get insightful reports you can share with your team.
Connect your cluster and start monitoring your K8s costs right away:
1. Overview
Libraries are an essential component of any Linux system. This is because they provide various functions and routines which are reusable by multiple software applications. So, as a Linux administrator, keeping track of library versions is crucial for ensuring compatibility between the library and its dependent software.
In this tutorial, we’ll discuss how to check for the version of a library using the dpkg and apt commands on the command line. These commands contain a variety of options that we’ll also discuss. We’ll mainly focus on the Debian and Ubuntu Linux distributions.
2. Using the dpkg Command
The dpkg command is a low-level package management tool used to manage packages in Debian-based systems, including Ubuntu. By using dpkg, we can see the version of a library installed on our system.
Before we proceed, let’s note that the dpkg command has more than one syntax we can use to check for the library version.
2.1. Using dpkg
First, there is the dpkg command with the -s option:
Here, we use the -s option to instruct dpkg to display details about the library.
So, let’s use the above syntax to check for the version of the libc6 library:
$ dpkg -s libc6 Package: libc6 Status: install ok installed Version: 2.35-0ubuntu3.1 . Original-Vcs-Browser: https://salsa.debian.org/glibc-team/glibc Original-Vcs-Git: https://salsa.debian.org/glibc-team/glibc.git
In the example above, we see detailed information about the libc6 library including its version number. What’s more, we can see the installed version of the libc6 library is 2.35-0ubuntu3.1.
2.2. Using dpkg With grep
Next, we’ll use the dpkg command with its -l option in collaboration with the grep command:
$ dpkg -l | grep [ library_name ]
Here, -l instructs dpkg to list a comprehensive summary of the library. Also, we use the grep command to search for the library_name in our summary output.
So, let’s use the syntax above to check for the version of the libc6 library installed on our system:
$ dpkg -l | grep libc6 ii libc6:amd64 2.35-0ubuntu3.1 amd64 GNU C Library: Shared libraries ii libc6-dbg:amd64 2.35-0ubuntu3.1 amd64 GNU C Library: detached debugging symbols
Using the command above, we display information about the libc6 library including the version number. To be specific, the version number of the libc6 library as displayed above is 2.35-0ubuntu3.1. However, this isn’t such a precise method.
2.3. Using dpkg-query
Finally, we can use the dpkg-query command to check for the version of a library. In fact, we use dpkg-query to get information about libraries listed in the dpkg database.
To be precise, we’ll use the dpkg-query command in collaboration with the -W option to display information about a library:
$ dpkg-query -W libc6 libc6:amd64 2.35-0ubuntu3.1
As we can see from the output above, we passed the libc6 library name and got the same version number as before.
3. Using the apt Command
The apt command is a high-level package management tool used to manage regular and library packages on Debian-based Linux systems. In this section, we’ll use it to check for the version of a library installed on our system from its package.
We use the apt command with the show option:
Here, we include the show option to instruct apt to display details about a library.
So, let’s provide libc6 as the library name:
$ apt show libc6 Package: libc6 Version: 2.35-0ubuntu3.1 . Original-Vcs-Git: https://salsa.debian.org/glibc-team/glibc.git Download-Size: 3,235 kB
From the above output, we can see the version number, 2.35-Oubuntu3.1, of the installed libc6 library along with some additional information.
Other than checking the version of a library, we can also use the apt command to update a library to its latest version. For this, we first run the sudo apt update command followed by the sudo apt upgrade command with the name of the library we’d like to update:
Using the above commands, we’re able to upgrade the libc6 library to its latest version.
4. Conclusion
In this article, we discussed how to check the version of a library in Linux using the dpkg and apt commands.
Additionally, we looked at some of the options these commands provide. Also, we briefly saw how we can use the apt command to ensure that a library is up-to-date. Consequently, this knowledge is important as it helps ensure that library-dependent applications function as expected.
Find out library version
I want to find out what version of a C library is installed in my system (Ubuntu 12.04). In particular, I’m interested in libnuma. What is the proper way to do it?
cd /usr/lib ls -l libnuma* -rw-r--r-- 1 root root 70312 Feb 8 2012 libnuma.a lrwxrwxrwx 1 root root 12 Feb 8 2012 libnuma.so -> libnuma.so.1 -rw-r--r-- 1 root root 43976 Feb 8 2012 libnuma.so.1
4 Answers 4
I would use dpkg -l | grep libnuma1 to get the version.
As an example, I have ran dpkg -l on xterm and you can see that I’m running versoin 278-4 of xterm.
# dpkg -l | grep xterm ii lxterminal 0.1.11-4 amd64 LXDE terminal emulator ii xterm 278-4 amd64 X terminal emulator
This works most of the time but not applicable when you compile and install the library, because dpkg does not care about libs/apps not installed by dpkg
While @SuB is correct, the fact is that without a packaging system, there’s no way to know what release an individual library was built from, as that information is managed by the packaging system and not contained in the library. The library itself only knows its API version (the number after the .so ). When you compile and install a library yourself, it’s up to you to keep track of where it came from (which is why packaging systems were created).
It gives me the output but at the beginning of the output there are these two lines. ldconfig: Can’t stat /libx32: No such file or directory . ldconfig: Can’t stat /usr/libx32: No such file or directory . Is that something to worry about?
ldconfig -v | grep libnuma shows libnuma.so.1 -> libnuma.so.1.0.0 , but dpkg -l | grep libnuma1 shows ii libnuma1:amd64 2.0.12-1 . This variant does not look reliable.
The file name or contents won’t always keep track of the exact version, so you’d typically want to use the packaging system facilities. For Ubuntu, you can either go to packages.ubuntu.com, search for your file, and see what version of the package is in your version of Ubuntu.
Or from the command line, you can first search for the name of the associated package using dpkg -S /usr/lib/libnuma.so.1 , which probably returns libnuma1 as the package name. Then run apt-cache showpkg libnuma1 to find the package version. The apt-cache output can be pretty long, but the version should be in the first few lines.
You must log in to answer this question.
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.14.43533
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.