Friday, September 4, 2015

Library hierarchy in Linux

A library is a file containing compiled code from various object files stuffed into a single file

a library (or Program Library) can be of two types :
  1. Shared Library
  2. Static Library

 

 Static libraries can be beneficial in small programs where minimal functionality is needed.Nowadays these types are not used.

Shared Libraries:

Shared libraries can reduce the memory footprint of the program,This is because multiple programs can use a shared library simultaneously; therefore, only one copy of the library is needed in memory at a time.

GNU/Linux provides two ways to deal with shared libraries
You can dynamically link your program with the shared library and have Linux load the library upon execution (unless it's already in memory).

Or the program to selectively call functions with the library in a process called dynamic loading. With dynamic loading, a program can load a specific library (unless already loaded), and then call a particular function within that library.

 


In Linux  
 
ld.so  dynamic linker/loader
 
This loads  the  shared  libraries  needed by a program, prepares the program to 
run, and then runs it.


The necessary shared libraries needed by the program are  searched  for in the 
following order
 
       o      From the cache file /etc/ld.so.cache which contains  a  compiled
              list  of  candidate  libraries previously found in the augmented
              library path.

       o      In the default path /lib, and then /usr/lib. 




         /lib/ld.so              a.out dynamic linker/loader
       /lib/ld-linux.so.*   ELF dynamic linker/loader
       /etc/ld.so.cache    File containing a compiled list of  directories  in which  to  search for 
                                    libraries and an ordered list of candidate libraries.

  • Update the dynamic loader cache by running:   ldconfig

No comments:

Post a Comment