[PLUG] RPM/lib question

Terry Griffin griffint at pobox.com
Sun Mar 20 05:37:20 UTC 2005


On Saturday 19 March 2005 5:24 pm, Paul Heinlein wrote:
> On Sat, 19 Mar 2005, Terry Griffin wrote:
> > I don't know where you get that. If you say:
> >
> >   gcc somefile.c -lsomelib
> >
> > then ld is going to look for libsomelib.so. If it finds it then
> > that's the reference that will go in the binary even if libsomelib.so
> > is a symbolic link to libsomelib.so.X (which it often is).
>
> Without trying to sound like I know what's *supposed* to happen,
> that's not the way it works on my box (CentOS 4.0, gcc 3.4.3, glibc
> 2.3.4). If I do a general -lz, it appears to me that the linker
> unravels the symlinks. Or is this a bad test?
>
> [tmp]$ cat t.c
> #include <stdio.h>
> int main() { printf( "Hello, world!\n" ); return 0; }
>
> [tmp]$ ls -og /usr/lib/libz.so
> lrwxrwxrwx  1 15 Mar 18 13:54 /usr/lib/libz.so -> libz.so.1.2.1.2*
>
> [tmp]$ gcc -o t -lz t.c
>
> [tmp]$ file t
> t: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for
> GNU/Linux 2.2.5, dynamically linked (uses shared libs), not stripped
>
> [tmp]$ ldd t
>          libz.so.1 => /usr/lib/libz.so.1 (0x00850000)
>          libc.so.6 => /lib/tls/libc.so.6 (0x00631000)
>          /lib/ld-linux.so.2 (0x00618000)
>
> [tmp]$ strings t | grep libz
> libz.so.1
>
> -- Paul Heinlein <heinlein at madboa.com>

Curious. I get that with libz also (FC3). But if I build my own .so
library then gcc behaves in the way I described. In fact I can mix
libz and my shared library in a single app and get the two different
types of references in the app's binary.

The possibility that it's following the symlinks doesn't make sense.
My libz symlinks are:

  /usr/lib/libz.so -> libz.so.1.2.1.2
  /usr/lib/libz.so.1 -> libz.so.1.2.1.2

The -lz switch would take you to libz.so. From there gcc could
easily hop to libz.so.1.2.1.2, but getting from there back to
libz.so.1 would be very weird and very inefficient. But somehow
that's what ends up in the app binary.

There's some magic going on under the hood I think.

Terry



More information about the PLUG mailing list