Site icon

Linux Dynamic Library Concepts

This article provides information about static, dynamic and shared libraries in linux. Identifying dynamic libraries required by an application. When and how these can be used.

I discussed about Linux build terminology,tool chain,static and dynamic libraries in Linux Development Process. I also discussed about command nm in  Embedded Programming Concepts-DWARF .

When to use nm and when readelf/objdump ?

You may rarely required nm command , readelf/objdump is sufficient to fetch required information from executable. As an experiment, Try both nm and readelf in any shared library.

When to use static library ?

If a particular module is compact and is specific to application, It can be compiled as static(*.a) library.

How Dynamic Library concept work ?

There are two possibilities :

How to check the required shared library by any linux application ?

We can use readelf, objdump or ldd

How Linux application find required dynamically linked shared libraries?

All library paths are cached in advance to avoid any performance issue when application binary executes. You may check this using ldconfig -p command. ldconfig can also be used to build this cache when a new library is loaded.  Library path is defined at /etc/ld.so.conf   .

One can define  environment variable LD_LIBRARY_PATH also to set the library path. You may check if this was set using env command.Linux will search path mentioned on LD_LIBRARY_PATH first before searching standard library paths. It can be used to test non-standard libraries, backward compatibility,new feature test or relocation of standard library.

Analysis with GDB

Program under discussion is as follows :

#include<stdio.h>
#include<math.h>
void main()
{
   int number;
   float val;
   printf("Please provide number :");
   scanf("%d",&number);
   val=sqrt(number);
   printf("Number=%d, Sqrt value=%f \r\n",number,val);
}

Useful GDB Commands

References :

I have discussed this article at  Linux Library working with Examples video.

 

Thanks for reading till end. I am trying to improve usability of my  site. Did you find this discussion helpful ? If so,  Please subscribe to YouTube channel Embedkari as well for additional embedded related stuff.

Exit mobile version