22

When building an application using g++, I am not explicitly passing the libc library as a library to link against in the same way you would do it for other libraries (like passing -lpthread for example).

I know that libc has the libc.so.6 so name, but I am aware that this is not actually a library but something like a pointer to another version of libc (such as libc-2.15.so).

If I had multiple versions of libc on my computer, how can I tell which one actually gets used using libc.so.6?

1 Answer 1

23

ldd should be the tool of your choice. That gives you the shared library actually linked.

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

In case of the libc you can simply run the .so file and will be told the library version.

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.
3
  • 1
    Thanks for the answer. Can you provide some information what the ldd output tells me? Does it mean that testendian requires GLIBC_2.3 or GLIBC_2.2.5?
    – bonanza
    Jul 6, 2016 at 6:55
  • I'm reasonably sure, it means that the program needs GLIBC 2.2.5 and the library loader ld-linux-x86-64 was build with GLIBC_2.3. So both in a way. But take that with a grain of salt, as I didn't find a reference.
    – con-f-use
    Jul 6, 2016 at 7:52
  • 1
    Works great for dynamic executables, but not so much for static ones! (I need to test what I'm linking against becauses of a gcc warning: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking)
    – jpaugh
    Nov 22, 2016 at 19:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .