你如何找到你的 linux 机器上安装了哪个版本的 libstdc++ 库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10354636/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you find what version of libstdc++ library is installed on your linux machine?
提问by Trevor Boyd Smith
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.
我找到了以下命令:strings /usr/lib/libstdc++.so.6 | grep GLIBC
from here. 它似乎有效,但这是一种临时/启发式方法。
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?
有没有具体的命令可以用来查询C++的库版本?或者我找到的方法是接受的方法?
回答by Edvard Pedersen
You could use g++ --version
in combination with the GCC ABI docsto find out.
您可以g++ --version
结合GCC ABI 文档来查找。
回答by Dmitri Chubarov
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
libstdc++ 3.4.0 及以上版本的兼容版本列表由
$ 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.
对于早期版本,GLIBCPP
定义了符号。
The date stamp of the library is defined in a macro __GLIBCXX__
or __GLIBCPP__
depending on the version:
库的日期戳在宏中定义__GLIBCXX__
或__GLIBCPP__
取决于版本:
// 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:
文档中列出了 libstdc++ 版本的日期戳表:
回答by Petesh
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.
我倾向于使用的机制是从 libstdc++readelf -V
转储.gnu.version
信息,然后匹配GLIBCXX_
提取的最大值的查找表的组合。
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:
如果您的版本sort
太旧而无法-V
选择(按版本号排序),那么您可以使用:
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.
而不是 ,sort -u -V
按最多 4 个版本数字排序。
In general, matching the ABI version should be good enough.
一般来说,匹配ABI版本应该就足够了。
If you're trying to track down the libstdc++.so.<VERSION>
, though, you can use a little bash like:
如果你想追查libstdc++.so.<VERSION>
,不过,你可以使用一个小的bash,如:
file=/usr/lib/libstdc++.so.6
while [ -h $file ]; do file=$(ls -l $file | sed -n 's/.*-> //p'); done
echo ${file#*.so.}
so for my system this yielded 6.0.10
.
所以对于我的系统,这产生了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:
但是,如果您试图让在 systemX 上编译的二进制文件在 systemY 上运行,那么这些事情只会让您走到这一步。在这些情况下,携带用于应用程序的 libstdc++.so 的副本,然后使用执行以下操作的运行脚本:
export LD_LIBRARY_PATH=<directory of stashed libstdc++.so>
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.
通常可以解决盒子上的 .so 与应用程序版本不兼容的问题。对于更极端的环境差异,我倾向于只添加所有依赖库,直到应用程序正常运行。这是 linux 等效的解决方法,对于 Windows,将被视为dll 地狱。
回答by Jonathan Wakely
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
.
共享库soname?这是文件名的一部分,libstdc++.so.6
,或由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.
这告诉您它是 6.0.16,这是版本的第 16 次修订libstdc++.so.6
,对应于GLIBCXX_3.4.16
符号版本。
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:
或者你的意思是它来自哪个版本?它是 GCC 的一部分,因此它与 GCC 的版本相同,因此除非您通过安装不匹配的版本来搞砸您的系统,g++
并且libstdc++.so
您可以从以下位置获得:
$ g++ -dumpversion
4.6.3
Or, on most distros, you can just ask the package manager. On my Fedora host that's
或者,在大多数发行版中,您可以询问包管理器。在我的 Fedora 主机上
$ 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
正如其他答案所说,您可以通过检查ABI 文档将版本映射到库版本