101 2.3 manage shared libraries

  • View

  • Download

Embed Size (px)


  • Linux Essenciais and System Administration

  • Key Knowledge Areas

    Identify shared libraries. Identify the typical locations of system libraries. Load shared libraries. Linux Installation and Package ManagementManage shared librariesTerms and Utilities

    ldd ldconfig /etc/ld.so.conf LD_LIBRARY_PATH *

  • Manage shared librariesWhen source code is written, programmers do not rewrite code for common operations.

    These operations are written once and used again by many other programmers. These common operations are stored in what are called libraries.

    For an application to successfully compile and run, it needs access to the libraries it waswritten to use.Dependencies of executable programs on shared libraries*Statically compiled applications.Some source code compiles libraries into final executable - Dont need the libraries to run.dynamically compiled applications.Applications linked to the libraries during compile and must access to the library files later.statically compiling makes the application larger than a dynamically compiled version.

  • Manage shared librariesEx. on many Linux systems is ln cmd (/bin/ln), which creates links between files, either hard links or soft (or symbolic) links.

    This cmd uses shared libraries. Shared libraries involve symbolic links between a generic name for the library and a specific level of the library, if not present or broken, the ln command itself might be inoperative.Progs with dynamically shared libraries and statically linked versions *To protect against this possibility, some Linux systems include a statically linked version of the ln program as the sln program (/sbin/sln).Example: Fedora12 64-bit - difference in size between dynamically linked ln and statically linked sln.yourname@yourcomp~$ ls -l /sbin/sln /bin/ln

    -rwxr-xr-x. 1 root root 47384 2010-01-12 09:35 /bin/ln-rwxr-xr-x. 1 root root 603680 2010-01-04 09:07 /sbin/slnEx:

    Statically linked programs are likely to be larger

  • Manage shared librariesLinuxs shared libraries are stored in several paths:

    /lib Main shared libraries/usr/lib Supplemental libraries/usr/X11R6/lib Shared libraries for X WindowPath and Naming convention*Shared libraries naming convention:

    libraryname-major-minor-patch.so (so extension stands for shared object)

    Example: libcrypt-2-1-3.soname of library: libcrypt. major version: 2 minor version: 1 patch level: 3In many cases theres symbolic links to the shared library. These are named as:



    These links allow software to point to them instead of the actual file. This way the minor version and patch level can change without breaking the association.

  • Manage shared librariesLinux systems run on hardware that supports 32-bit and 64-bit executables. Many libraries are thus compiled in 32-bit and 64-bit versions.ldd Output: Viewing required shared libraries*64-bit versions are stored under /lib64; 32-bit versions live in the traditional /lib tree.Libraries /lib64/libc-2.11.1.so and /lib/libc-2.11.1.so allow C Progs of 64-bit and 32-bit to run on Linux 64-bit System. To see which libraries an application uses, use command: ldd file_name~/usr/bin# ldd wget

    libc.so.6 => /lib/libc.so.6 (0x40020000)/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)Ex:

    wget uses libraries libc.so version 6 and ld-linux.so version 2.

  • Manage shared librariesldd Output: Dependencies between libraries*Left hand column indicates what the program would like to be linked to (no path name given), Right hand column shows what the program will actually be linked to (full path and often a symbolic link)~/usr/bin# ldd /bin/bash

    libtermcap.so.2 => /lib/libtermcap.so.2 (0x40024000)libdl.so.2 => /lib/libdl.so.2 (0x40028000)libc.so.6 => /lib/libc.so.6 (0x4002b000)/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)Ex:

    When programs are loaded into memory, part of loading process is to make sure that relevant shared libraries are loaded when the program loads.

    A library can require other libraries. Dependencies are normal for large applications. A program may use a graphics library, which can use the X11 library, which in turn uses the C library.~$ ls -lg /lib/libc.so.6lrwxrwxrwx 1 root 14 Oct 14 10:47 /lib/libc.so.6 -> libc-2.2.93.so~$ ls -lg /lib/libc-2.2.93.so-rwxr-xr-x 1 root 1327065 Sep 6 2002 /lib/libc-2.2.93.sobash asked to link to libc.so.6, and it ended up linking to /lib/libc2.2.93.so.

  • Manage shared librariesldd Output: types of information*Ex:

    In Fedora 12 64-bit system (echidna). ln cmd needs 3 shared libraries:~$ ldd /bin/lnlinux-vdso.so.1 => (0x00007fff644af000)libc.so.6 => /lib64/libc.so.6 (0x00000037eb800000)/lib64/ld-linux-x86-64.so.2 (0x00000037eb400000)1.(linux-vdso.so.1) is the Linux Virtual Dynamic Shared Object.Necessary logic to allow user programs to access system functions through fastest means available on the processor.Either by interrupt, or for most newer CPUs by fast system call. Types of ldd info: (1) Linux Virtual Dynamic Shared Objects; (2) Pointers; (3) Absolute paths.2.(libc.so.6) has a pointer to /lib64/libc.so.6.3.(/lib64/ld-linux-x86-64.so.2) is the absolute path to another library.~$ ls -l /lib64/libc.so.6 /lib64/ld-linux-x86-64.so.2lrwxrwxrwx. 1 root root 12 2010-01-14 14:24 /lib64/ld-linux-x86-64.so.2 -> ld-2.11.1.solrwxrwxrwx. 1 root root 14 2010-01-14 14:24 /lib64/libc.so.6 -> libc-2.11.1.so ls -l cmd shows that last 2 libraries are, in turn, symbolic links to specific versions of the libraries.

  • Manage shared librariesConfiguring shared libraries*If a shared library is installed manually by editing the LIBRARY CONFIGURATION FILE , you must manually inform the system to use the new libraries. (with ldconfig)

    The LIBRARY CONFIGURATION FILE is in:/etc/ld.so.conf and /etc/ld.so.cache - contains the directories to be searched for shared libraries./etc/ld.so.conf specifies that all the .conf files from subdirectory ld.so.conf.d should be included. Older systems may have all entries in /etc/ld/so/conf and not include entries from /etc/ld.so.conf.dEx:

    ~$ cat /etc/ld.so.conf

    include ld.so.conf.d/*.conf ~$ ls /etc/ld.so.conf.d/*.conf


  • Manage shared librariesConfiguring shared libraries*Command ldconfig Processes ld.so.conf including the file libraries from the file, and from the trusted directories: /lib and /usr/lib, and creates the ld.so.cache.Ex:

    ~$In summary - The ld.so.cache file is created from the ld.so.conf file by using ldconfig.Any time that ld.so.conf file is changed, the cache file needs to be updated - Using ldconfig

  • Manage shared librariesLoading and setting specific libraries paths*Applications can be made to load libraries from directories not listed in /etc/ld.so.conf older apps that need specific library, developing versions of shared libraries, running scripts with product-specific shared libraries installed in /opt.

    If the library is not in the standard path, you can search and add the nonstandard path with:LD_LIBRARY_PATH environment variable.export LD_LIBRARY_PATH=/usr/lib/oldstuff:/opt/IBM/AgentController/libIf theres more than 1 list of directories to search, separate them by colon.Export LD_LIBRARY_PATH=/usr/newpathLD_PRELOAD: Specifies libraries containing symbols that override symbols in the real libraries. LD_PRELOAD is seldom used except for debugging and compatibility applications (SOCKS proxy support).Add the /usr/newpath to the list of searched directories for libraries.Ex:


  • Fim de sesso*