怎样知道你的应用程序依赖于那个版本的GCC和那个版本的ABI

其实很简单,让我们反着来推一下。
我们先看看一短源代码是如果编译的,

#include <iostream>

int main()
{ 
    std::cout << "hello" << std::endl; return 0; 
}

编译:

%g++ hello.cc -o hello.out

使用ldd查看它依赖的C++库:

%ldd hello.out
    libstdc++.so.5 => /usr/lib/libstdc++.so.5 (0x00764000)
    libm.so.6 => /lib/tls/libm.so.6 (0x004a8000)
    libgcc_s.so.1 => /mnt/hd/bld/gcc/gcc/libgcc_s.so.1 (0x40016000)
    libc.so.6 => /lib/tls/libc.so.6 (0x0036d000)
    /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x00355000)

使用nm可以看到这个程序是和那个版本的C++绑定到一起的( the executable is versioned),是和GLIBCXX_3.4 绑定的,它对应的gcc版本号是GCC 3.4.0

%nm hello.out

U _ZNSt8ios_base4InitC1Ev@@GLIBCXX_3.4 

和GCC一样,下面是我的一个程序的readelf输出,这个程序是和ABI_1.3绑定的,ABI_1.3对应的GCC版本可以在下面的链接中找到。

readelf -a xxx | grep CXX
20: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND __cxa_end_catch@CXXABI_1.3 (2)

https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html

Use readelf -a and objdump -x to inspect ELF files in preference to
strings.

Actually, all the GLIBCXX_* versions don’t apply to the entire
library, but to each symbol (symbol versioning, see DSO-howto). So you
can have e.g: std::char_traits::eq@@GLIBCXX_3.4.5 and
std::ios_base::Init::~Init()@@GLIBCXX_3.4 on the same library file.

The fact that your program needs GLIBCXX_3.4.9 probably means that it
has been linked against a symbol that has been introduced/has changed
semantics on GLIBCXX_3.4.9.

https://stackoverflow.com/questions/4133674/glibcxx-versions

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值