如何找到我的应用程序链接到的libc版本?


14

使用g ++构建应用程序时,我没有显式地将libc库作为与其他库相同的链接方式传递-lpthread给库(例如,传递)。我知道libc的名称是so,libc.so.6但我知道这实际上不是库,而是类似指向另一个版本的libc(例如libc-2.15.so)的指针。我的问题是,如果我的计算机上有多个版本的libc,我该如何确定实际上通过哪个链接到了哪个版本libc.so.6。

Answers:


16

ldd应该是您选择的工具。这使您可以实际链接共享库。

confus@confusion:~/misc/test$ ldd -r -v testendian
    linux-vdso.so.1 =>  (0x00007fffbcfff000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f1a5a4c5000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f1a5a8a5000)

    Version information:
    ./testendian:
        libc.so.6 (GLIBC_2.2.5) => /lib/x86_64-linux-gnu/libc.so.6
    /lib/x86_64-linux-gnu/libc.so.6:
        ld-linux-x86-64.so.2 (GLIBC_2.3) => /lib64/ld-linux-x86-64.so.2
        ld-linux-x86-64.so.2 (GLIBC_PRIVATE) => /lib64/ld-linux-x86-64.so.2

如果使用libc,则只需运行该.so文件,系统就会告知库版本。

confus@confusion:~/misc/test$ /lib/x86_64-linux-gnu/libc.so.6 
GNU C Library (Ubuntu EGLIBC 2.15-0ubuntu10) stable release version 2.15, by Roland McGrath et al.

我确实了解过ldd,但不知道您只能运行一个库-谢谢。不幸的是,从运行库中不显示我的版本输出....
— mathematician1975

不用理会我是个白痴-感谢您的回答!
— mathematician1975

1
感谢您的回答。您能否提供一些信息,ldd输出告诉我什么?这是否意味着testendian需要GLIBC_2.3或GLIBC_2.2.5?
— bonanza

我可以肯定地说,这意味着该程序需要GLIBC 2.2.5,并且库加载程序ld-linux-x86-64 是使用GLIBC_2.3构建的。所以两者都有某种方式。但是请带一点盐,因为我没有找到参考。
— con-f-use

适用于动态可执行文件,但不适用于静态可执行文件!(我需要测试什么,我链接到的GCC警告becauses: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking)
— jpaugh
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.