15

I recently read a lot about shared libraries on Linux, and here is what I learnt:

  • A shared library should embed a soname including its major version number. Something like: libfoo.so.1
  • Its real filename should also include a minor version number. Something like: libfoo.so.1.0
  • When the library file is copied to, say /usr/local/lib, if ldconfig is run, it will read the soname and create a symlink named libfoo.so.1 pointing to libfoo.so.1.0.
  • If one wants to use this library for its developments it should first create a symlink without any version number to the real file, say libfoo.so pointing to libfoo.so.1.0. This is usually done by the development package (when the library is packaged).

Is this correct ?

ereOn
  • 53,676
  • 39
  • 161
  • 238
  • 2
    You are correct but see http://www.nondot.org/sabre/Mirrored/libtool-2.1a/libtool_6.html anyhow :) – ismail Jan 21 '11 at 09:23
  • @Navi: Several links, man pages (`ldconfig`, `gcc`) and I experienced myself. This link was helpful: http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html – ereOn Jan 21 '11 at 09:47
  • @İsmail 'cartman' Dönmez: Do not hesitate to post this as an answer (after all you perfectly answer my question ;)). – ereOn Jan 21 '11 at 09:48
  • I'll pass on that since actually one part I'd have to explain is when you should bump your library version, a good answer should include that :) – ismail Jan 21 '11 at 09:56

1 Answers1

25

Suggested reading:

Ulrich Drepper's How to write shared libraries: http://www.akkadia.org/drepper/dsohowto.pdf

Ulrich Drepper's Good Practices in library design, implementation, and maintenance: http://www.akkadia.org/drepper/goodpractice.pdf

dsohowto is much more detailed. goodpractice is a quick read.

sarnold
  • 102,305
  • 22
  • 181
  • 238