Hands-On Lab Manage Shared Libraries
Hands-On Lab Manage Shared Libraries
Manage
Shared
Libraries
Contents Related Courses
Library Locations 1
LPIC-1 Sysem
Linking to Shared Objects 2 Administrator -
Exam 101
Static Linking 2
Dynamic Linking 2
Related Videos
Managing Libraries 2
Need Help?
Linux Academy
Community
Shared libraries are files that contain reusable functions for use by other applications. Library files use the
.so extension and often contain version information – libraryname-version.so. In this lab, we learn
about libraries, then explore how to best manage and configure libraries and the dynamic linker.
Log in to the server using the credentials provided on the Hands-on Lab page. Use sudo su - to switch
to the root user.
Library Locations
Shared libraries are traditionally contained in the /lib, /lib64, /usr/lib, and /usr/lib64 directories.
Occasionally they are also found in /usr/local/lib, typically when installed with a third-party
application.
As we can see, the majority of these libraries contain specific version numbers at the end of their filenames,
-1-
Manage Shared Libraries Linux Academy
Static Linking
Static linking is when an application packages a full version of the library within it. By using static linking,
we can ensure that the application always has the appropriate version of the library available; although,
this process increases the size of the application. Additionally, any feature upgrades and bug fixes added to
that library later will not to included in the application-packaged library unless the application maintainers
upgrade the library and repackage the application with the included changes.
Dynamic Linking
Dynamic linking is when an application uses the version of the shared library already on the computer.
Generally, this is where we see the symlinking of library files with standard names to the name, versioned
file.
When calling to these libraries, the dynamic linker, ld.so, is used. This is a background service that copies
the library to the computer’s RAM for use by the application.
Managing Libraries
Determine Needed Libraries
To determine which application uses what libraries, use the ldd command. This can help if we are uncertain
if an application has all its needed libraries. We need to know the full path to the application to use this.
First, determine the application path, then use it to determine the libraries needed for shhd:
-2-
Manage Shared Libraries Linux Academy
sshd requires a number of shared objects. If we were using a bare installation and needed to install the
sshd package, we could then expect that these libraries already exist on the system, and, if they do not, that
they will be downloaded at the time sshd is acquired.
The ldconfig command is used as part of the exit script at the end of an application installation and
normally does not have to be run on its own. However, if you have any doubts about any shared objects
being updated or you made manual changes to the ld.so.conf file and need to update the cache, this
command should be used. This will update the ld.so.cache file:
[root@ip] cd /etc/
[root@ip] ls -al ld.so.cache
-rw-r--r--. 1 root root 17917 Mar 7 04:22 ld.so.cache
[root@ip] ldconfig
[root@ip] ls -al ld.so.cache
-rw-r--r-- 1 root root 17917 Apr 28 19:15 ld.so.cache
-3-
Manage Shared Libraries Linux Academy
Additionally, if we want to force the dynamic linker to look in other directories, we can alter the ld.so.
conf file. cat out this file:
[root@ip] cd ld.so.conf.d
[root@ip] ls -al
total 24
drwxr-xr-x. 2 root root 4096 Mar 7 04:55 .
drwxr-xr-x. 70 root root 4096 Apr 28 19:15 ..
-r--r--r--. 1 root root 324 May 31 2016 kernel-2.6.32-642.1.1.el6.
x86_64.conf
-r--r--r--. 1 root root 324 Feb 24 14:37 kernel-2.6.32-642.15.1.el6.
x86_64.conf
-r--r--r--. 1 root root 324 Feb 27 03:48 kernel-ml-4.10.1-1.el6.
elrepo.x86_64.conf
-rw-r--r--. 1 root root 17 Jan 26 22:25 mysql-x86_64.conf
Here we see a number of configurations for third-party application and the kernel. Should we view one of
these, we can see which directory is being scanned:
Alternatively, we can alter the LD_LIBRARY_PATH environmental variable to determine which directories
are looked at for shared objects. To see what populates this variable currently, use:
We can customize this by overriding the path or appending new ones to the existing path. This process is
explained later in the course.
Review
Libraries provide applications with reusable functions. We now know how to find the directories containing
these functions and how applications link to these libraries, as well as how to determine needed libraries
and configure the behavior of the dynamic linker. This lab has been completed!
-4-