Understanding Shared Libraries

Library – Usually a system library is a collection of program functions. From programming basics, we can say functions are self-contained code modules or code blocks that perform a certain task within an application. Reason to use function is to use the same function in multiple other files and programs. Linux supports static libraries which are copied into an application when it is compiled. The other are called shared libraries where functions are copied into memory and called when the program is launched (so called loading a library).

Library cache – Catalog of library directories and all libraries contained within those directories. System reads this cache to find needed libraries when loading programs. It finds and loads libraries quickly rather than searching them through the whole system. When new library is added to the system, this library cache file must be updated. To update it, use ldconfig command. When we pull packages from repositories, this command is run automatically and updates all downloaded libraries to its library cache. To see what library files are cached, use ldconfig -v command. The library data is stored in /etc/ld.so.cache file. If you create new library, make new file in /etc/ld.so.conf.d/ directory which contains path to your new library file. Then, run ldconfigv to update cache and it should work.

A shared library file has following filename format:


The “so” stands for shared library, and for static libraries there would be “a” character. When a program is using shared function, system searches for function’s library file. Locations where system looks for that library file are as follows:

  2. Program’s path environment variable
  3. /etc/ld.so.conf.d/ directory
  4. /etc/ld.so.conf file
  5. /lib*/ directory
  6. /usr/lib*/ directory

When the program starts, dynamic linker or dynamic loader searches program’s needed library functions. Once the library is found, dynamic linker copies them into memory and connect them with the program. Dynamic linker is executable with name ld.so or ld-linux.so

If library is missing, use ldd utility. Here are all libraries for htop program:

[aldin@arch ~]$ ldd /usr/bin/htop
	linux-vdso.so.1 (0x00007ffc7e1eb000)
	libncursesw.so.6 => /usr/lib/libncursesw.so.6 (0x00007f4c647f4000)
	libm.so.6 => /usr/lib/libm.so.6 (0x00007f4c646ae000)
	libnl-3.so.200 => /usr/lib/libnl-3.so.200 (0x00007f4c6468a000)
	libnl-genl-3.so.200 => /usr/lib/libnl-genl-3.so.200 (0x00007f4c64681000)
	libc.so.6 => /usr/lib/libc.so.6 (0x00007f4c644b8000)
	/lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007f4c648dc000)
	libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007f4c64496000)

One thought on “Understanding Shared Libraries

  1. Have you ever considered creating an e-book orr guest authoring on other sites?
    I have a blog based upon on the same information you disciss
    and would really like too have you share some stories/information. I know my viewers
    would valuee your work. If you’re even remotely interested, feel free to send
    me an email.
    php patterns

Leave a Reply