To find which library is being used you could run
Copy $ /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
Copy $ 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:
Copy// libdatestamp.cxx
#include <cstdio>
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:
Answer from Dima Chubarov on Stack OverflowTo find which library is being used you could run
Copy $ /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
Copy $ 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:
Copy// libdatestamp.cxx
#include <cstdio>
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:
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:
Copy$ 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:
Copy$ g++ -dumpversion
4.6.3
Or, on most distros, you can just ask the package manager. On my Fedora host that's
Copy$ 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
Is there a difference between libstdc++ and libstdc++11 in the current releases of gcc (or at least gcc >=8)?
I want to create libraries that support code using the C++17 standard.
I can't find any concise answer on which lib to use or if it even matters.
Resolving library version incompatibility for libstdc++.so on recent Ubuntu versions
gcc - What is libstdc++.so.6 and GLIBCXX_3.4.20? - Unix & Linux Stack Exchange
How can I have libstdc++ version and glibc version in profile
c++ - How to detect the libstdc++ version in Clang? - Stack Overflow
Clang does come with its own standard library implementation, it's called libc++. You can use it by adding -stdlib=libc++ to your compile command.
That being said, there are various ways to check Clang/libstdc++ C++ support:
- Clang has the
__has_featuremacro (and friends) that can be used to detect language features and language extenstions. - Libstdc++ has its own version macros, see the documentation. You'll need to include a libstdc++ header to get these defined though.
- GCC has its version macros which you already discovered, but those would need to be manually compared to the documentation.
And also, this took me 2 minutes of googling.
This is what I think would help. It prints the value of the _LIBCPP_VERSION macro:
#include <iostream>
#include <string>
using namespace std;
int main(int argc, const char * argv[])
{
cout<<"Value = "<<_LIBCPP_VERSION<<endl;
return 0;
}
Compile it again the version of clang you want the info for.
You look in the manual, specifically at http://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html which shows the library version numbers for each GCC release.
You can just check the GCC source code, for example the libstdc++/ChangeLog file that comes with it. It shouldn't be too hard to script that.
At first sight, libstdc++ isn't getting real version numbers anymore, they just use the source code repository revision id in the ChangeLog files.
Hi,
I would like to write a testing code that only works on newer libstdc++ ( GLIBCXX_VERSION > 3.4.29) and should fail with an older libstdc++ (GLIBCXX_VERSION = 3.4.25).
I'm using gcc-14 as the compiler and have tried many new C++20 and C++23 features, like ranges, concepts, std::println. All of them still run successfully with the old version libstdc++. I also use ldd command to make sure the executable is indeed linked to the old libstdc++.
Does anyone know which new features do not work with the old libstdc++?
Why know this?
The installation of the latest version of Boost requires GLIBCXX_3.4.29 but the /usr/lib64/libstdc++.so.6 in my system only has GLIBCXX_3.4.25. I would like to write a test to show the system is now using a new libstdc++ instead of the old one.