The exact output from the various commands will vary depending on how your system is configured.
Solution for exercise 1. List dynamically linked shared objects
Listing 1 shows one way to go.
Listing 1. Use the ldd command to view libraries called by mkdir
[tbost@exercises ~]$ ldd /bin/mkdir
linux-gate.so.1 => (0x00d19000)
libselinux.so.1 => /lib/libselinux.so.1 (0x008e7000)
libc.so.6 => /lib/libc.so.6 (0x00d1d000)
libdl.so.2 => /lib/libdl.so.2 (0x00406000)
/lib/ld-linux.so.2 (0x00c53000)
|
Alternatively, the command shown in Listing 2 can list the
required shared libraries from mkdir.
Listing 2. Use the /lib/ld-linux.so.2 executable to view libraries called by mkdir
[tbost@exercises ~]$ /lib/ld-linux.so.2 --list /bin/mkdir
linux-gate.so.1 => (0x00cc6000)
libselinux.so.1 => /lib/libselinux.so.1 (0x00110000)
libc.so.6 => /lib/libc.so.6 (0x0026c000)
libdl.so.2 => /lib/libdl.so.2 (0x00ae8000)
/lib/ld-linux.so.2 (0x00866000)
|
Notice a pointer for each shared object in the lib directory in the second through fourth shared object. linux-gate.so.1 is considered a virtual dynamic shared object.
Solution for exercise 2. Find statically linked executables
Listing 3 shows one correct way to accomplish this.
Listing 3. Use the ldd command for zcat
[tbost@t60 bin]$ ldd /bin/zcat not a dynamic executable |
A statically linked executable is denoted with the not a dynamic
executable output: zcat is such an example.
Alternatively, you could use the command ldd /bin/* | less
to obtain a reference listing for all files in the /bin directory.
Solution for exercise 3. Find information about library caching
Listing 4 shows how to proceed.
Listing 4. Use the ldconfig command to view libraries in cache
[tbost@exercises ld.so.conf.d]$ ldconfig -p | grep libc.so.6 libc.so.6 (libc6, OS ABI: Linux 2.6.32) => /lib/libc.so.6 |
The key point is to use ldconfig -p. With the
exception of the virtual dynamic shared object, any other shared object output
from the ldd /bin/mkdir command will suffice.
Solution for exercise 4. Set an alternative shared library path
Listing 5 shows the commands to use.
Listing 5. Set the LD_LIBRARY_PATH variable
[tbost@exercises ld.so.conf.d]$ sudo mkdir -p /opt/foo/lib [tbost@exercises ~]$ sudo touch /opt/foo/lib/foo.so [tbost@exercises ~]$ export LD_LIBRARY_PATH=/opt/foo/lib |
The sequence of steps in exercise 4 is as follows:
- As sudo user, use the
mkdir -p /opt/foo/libcommand to create the parent directory foo along with the child directory lib. - As sudo user, use the
touchcommand to create an empty foo.so shared object file. - Set the global variable LD_LIBRARY_PATH to use /opt/foo/lib with the
exportcommand.
Solution for exercise 5. Create a symbolic link to a shared library
Listing 6 shows how to accomplish this.
Listing 6. Symbolically link a shared object
[tbost@exercises ~]$ sudo mv /opt/foo/lib/foo.so foo.so.old [tbost@exercises ~]$ sudo ln -s /lib/libcat.so /opt/foo/lib/foo.so [tbost@exercises ~]$ ls -l /opt/foo/lib/foo.so lrwxrwxrwx. 1 root root 14 May 15 13:31 /opt/foo/lib/foo.so -> /lib/libcat.so |
The sequence of steps in exercise 5 is as follows:
- As sudo, rename the original foo.so shared object to foo.so.old.
- As sudo, use the
ln -scommand to symbolically link the /lib/libcat.so shared object to /opt/foo/lib/foo.so. - The final command verifies that /opt/foo/lib/foo.so is now symbolically linked to /lib/libcat.so.