Shared libraries -- still a nightmare (more or less)

From: Carlos Moreno (moreno_at_mochima_dot_com_at_xx.xxx)
Date: 05/31/05


Date: Mon, 30 May 2005 21:01:35 -0400


I'm still struggling to understand this.

I read about -soname in the HOWTO, and in the man pages for ld,
but there's something that doesn't make sense in my head:

 From "man ld":

   -soname=name
      When creating an ELF shared object, set the internal DT_SONAME
      field to the specified name. When an executable is linked with a
      shared object which has a DT_SONAME field, then when the executable
      is run the dynamic linker will attempt to load the shared object
      specified by the DT_SONAME field rather than the using the file
      name given to the linker.

What I can't understand is: if I give an internal name different from
the filename, then how will it know/guess that this is the right .so
file to link to at runtime?

To further aggravate my confusion, they give an example!! (yes, I do
see the irony in this :-))

In the example (from the "library programming HOWTO"), they do:

-Wl,-soname,libmystuff.so.1 -o libmystuff.so.1.0.1 ....

If I do that and then run ldconfig, a symlink is created -- the symlink
is called .so.1 and points to .so.1.0.1

What's this useful for? It looks like they're talking about a situation
where an upgrade does not break binary compatibility? If so, then why
not simply overwriting the same .so.1 file?

I guess another part of my confusion comes from the following: what is
the role of the symlink libmystuff.so ??

If I have libs .so.1 .so.1.1 and .so.2 , normally I would see a symlink
.so pointing to the latest (.so.2 in this case). That means that at the
present time, anything linked to .so will use the functionality present
in .so.2

But what happens then when I install version 3 of that library? If I
now have .so.3 and the symlink .so is now made point to .so.3, are we
not breaking any applications that were previously linked to the
binary contents of the file .so.2 ?

I'm sooooooo confused :-(

Carlos

--