Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are good practices regarding shared libraries on Linux?

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 ?

like image 482
ereOn Avatar asked Jan 21 '11 09:01

ereOn


People also ask

How do shared libraries work on Linux?

Shared libraries are the most common way to manage dependencies on Linux systems. These shared resources are loaded into memory before the application starts, and when several processes require the same library, it will be loaded only once on the system. This feature saves on memory usage by the application.

What is the purpose of using shared libraries?

Shared Libraries are the libraries that can be linked to any program at run-time. They provide a means to use code that can be loaded anywhere in the memory. Once loaded, the shared library code can be used by any number of programs.

Which of the following is necessary to create a shared library?

The -shared or -dynamiclib option is required to create a shared library. The name of the source file is octagon.


1 Answers

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.

like image 92
sarnold Avatar answered Sep 23 '22 13:09

sarnold