– General Linux 1 – Manage Shared Libraries [3] (Linux Professional Institute Certification) a .˜. /V\ // \\ @._.@ from IBM developerWorks tutorial geoffrey robertson geoffrey@zip.com.au $Id: gl1.102.4.slides.tex,v 1.4 2003/05/30 05:09:04 waratah Exp $ c 2002 Geoffrey Robertson. Permission is granted to make and distribute verbatim copies or modified versions of this document provided that this copyright notice and this permission notice are preserved on all copies under the terms of the GNU General Public License as published by the Free Software Foundation—either version 2 of the License or (at your option) any later version. a Copyright 1 List of Slides 2 (2.2) 102 Installation & Package Mgt. [24] 2.102.1 Design hard disk layout [2] 2.102.2 Install a boot manager [3] 2.102.3 Make and install programs from source [5] 2.102.4 Manage Shared Libraries [3] 2.102.5 Use Debian package management [5] 2.102.6 Use Red Hat Package Manager (RPM) [6] 3 Manage Shared Libraries Objective Candidates should be able to determine the shared libraries that executable programs depend on and install them when necessary. Candidates should be able to state where system libraries are kept. 4 Manage Shared Libraries Key files, terms, and utilities ldd ldconfig /etc/ld.so.conf LD_LIBRARY_PATH 5 Manage Shared Libraries Resources of interest Shared-Library HOWTO : http://linuxdocs.org/HOWTOs/Program-Library-HOWTO/ LPI certification 102 exam prep, Part 1 : http://ibm.com/developerWorks 6 Introducing shared libraries On Linux systems there are two fundamentally different types of Linux executable programs. 7 Introducing shared libraries On Linux systems there are two fundamentally different types of Linux executable programs. statically linked executables : contain all the functions that they need to execute 7-a Introducing shared libraries On Linux systems there are two fundamentally different types of Linux executable programs. statically linked executables : contain all the functions that they need to execute dynamically linked executables : require libraries of functions 7-b Static vs. Dynamic Executables ldd We can use the ldd command to determine if a particular executable program is static: $ ldd /sbin/sln ← not a dynamic executable 8 Static vs. Dynamic Executables ldd We can use the ldd command to determine if a particular executable program is static: $ ldd /sbin/sln ← not a dynamic executable Relative Size $ ls -l /bin/ln /sbin/sln ← -rwxr-xr-x 1 root root 23000 Jan 14 00:36 /bin/ln -rwxr-xr-x 1 root root 381072 Jan 14 00:31 /sbin/sln 8-a Dynamically Linked Dependencies • To view a list of all the shared libraries upon which ln depends, use the ldd command: $ ldd /bin/ln ← libc.so.6 => /lib/libc.so.6 (0x40021000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000) 9 Dynamically Linked Dependencies • To view a list of all the shared libraries upon which ln depends, use the ldd command: $ ldd /bin/ln ← libc.so.6 => /lib/libc.so.6 (0x40021000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000) • As a rule, dynamically linked programs are much smaller than their statically-linked equivalents. 9-a Dynamically Linked Dependencies • To view a list of all the shared libraries upon which ln depends, use the ldd command: $ ldd /bin/ln ← libc.so.6 => /lib/libc.so.6 (0x40021000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000) • As a rule, dynamically linked programs are much smaller than their statically-linked equivalents. • /lib/ld-linux.so.2 is the loader 9-b The dynamic loader • The dynamic loader takes care of loading the shared libraries that dynamically linked executables need in order to run. 10 The dynamic loader • The dynamic loader takes care of loading the shared libraries that dynamically linked executables need in order to run. • The dynamic loader finds shared libraries thanks to two files – /etc/ld.so.conf and /etc/ld.so.cache. 10-a The dynamic loader • The dynamic loader takes care of loading the shared libraries that dynamically linked executables need in order to run. • The dynamic loader finds shared libraries thanks to two files – /etc/ld.so.conf and /etc/ld.so.cache. • The contents of /etc/ld.so.conf: cat /etc/ld.so.conf /usr/X11R6/lib /usr/lib/gcc-lib/i686-pc-linux-gnu/2.95.3 /usr/lib/mozilla /usr/lib/qt-x11-2.3.1/lib /usr/local/lib 10-b ld.so.cache Before the dynamic loader can ”see” this information, it must be converted into an ld.so.cache file. This is done by running the ldconfig command: $ ldconfig ← When ldconfig completes, you now have an up-to-date /etc/ld.so.cache file that reflects any changes you’ve made to /etc/ld.so.conf. 11 ldconfig tips To view all the shared libraries that ldconfig can ”see,” type: $ ldconfig -p | less ← Sometimes, you’ll want to tell the dynamic loader to try to use shared libraries in a specific directory before trying any of your /etc/ld.so.conf paths. For older application requiring older libraries. 12 LD LIBRARY PATH • To instruct the dynamic loader to check a certain directory first, set the LD LIBRARY PATH variable to the directories that you would like searched. 13 LD LIBRARY PATH • To instruct the dynamic loader to check a certain directory first, set the LD LIBRARY PATH variable to the directories that you would like searched. • Separate multiple paths using colons; for example: # export LD LIBRARY PATH="/usr/lib/old:/opt/lib" ← 13-a LD LIBRARY PATH • To instruct the dynamic loader to check a certain directory first, set the LD LIBRARY PATH variable to the directories that you would like searched. • Separate multiple paths using colons; for example: # export LD LIBRARY PATH="/usr/lib/old:/opt/lib" ← • After LD LIBRARY PATH has been exported, any executables started from the current shell will use libraries in /usr/lib/old or /opt/lib if possible, falling back to the directories specified in /etc/ld.so.conf if some shared library dependencies are still unsatisfied. 13-b Summary • ldd 14 Summary • ldd • Lists the required libraries 14-a Summary • ldd ld.so.conf • Lists the required libraries • 14-b Summary • ldd ld.so.conf • Lists the required libraries • • list of library paths 14-c Summary • ldd ld.so.conf ldconfig • Lists the required libraries • • list of library paths • 14-d Summary • ldd ld.so.conf ldconfig • Lists the required libraries • • list of library paths • • Updates /etc/ls.so.cache from ld.so.conf 14-e Summary • ldd ld.so.conf ldconfig LD LIBRARY PATH • Lists the required libraries • • list of library paths • • Updates /etc/ls.so.cache from ld.so.conf • 14-f Summary • ldd ld.so.conf ldconfig LD LIBRARY PATH • Lists the required libraries • • list of library paths • • Updates /etc/ls.so.cache from ld.so.conf • • Holds library path for current shell 14-g The End 15