How do Linux programs know where the library files are and how to call them?

98 Views Asked by At

When I install a program using apt-get install, it tells me which dependency libraries also need to be installed.

For example, Nginx requires libgd3 (3d graphics library) to be installed.

  1. When Nginx needs to call code in libgd3 how does it know where the file is and
  2. How does it actually go about it? I assume it must load it into the Nginx process heap and then use some kind of function table to make calls?

I am not sure how this process works, thanks.

2

There are 2 best solutions below

0
On

The libraries are in standard path usually /usr/lib which the linker searches during linking. The dynamic libraries are called shared objects in linux having the extension .so . Check this link to know more about Linux Libraries: http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html

0
On

Usually through the environment variable LD_LIBRARY_PATH which is set of directories where libraries should be searched for first

See what it is set to :

env | grep LD_LIBRARY_PATH

You can update the new location to search temporarily by

export $LD_LIBRARY_PATH = $LD_LIBRARY_PATH:/new/dir/to/look

There is every chance that this env variable is not present in your distro. So you can try the below

1) Add library directories to /etc/ld.so.conf or

2) add it to the library cache by using ldconfig

Please read more here

http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html