Send in your Unix questions today! |
See additional Unix tips and tricks
Every now and then I come across a system which, when I issue a request to clear the screen (i.e., the clear command), I get something like this instead:
oopsy# clear
ld.so.1: clear: fatal: libncurses.so.5: open failed: No such file or directory
Killed
Often, on encountering this problem, I simply growl, press enter a couple dozen times and continue working. When I'm in a particularly "fixit" mood, on the other hand, I figure I shouldn't be putting up with annoying configuration problems and decide to break my train of thought just long enough to tackle this distracting problem head-on.
So, what is going on when you get an error such as this?
First, we know it came about because I issued the "clear" command. Next, we see that the error was issued by ld.so.1 (the runtime linker). Third, we see that the linker wasn't able to open a particular shared object file; it couldn't find it. The shared object file, libncurses.so.5, as you might suspect is the curses library. Curses provides a set of functions that provide users with the ability to manipulate a terminal's display regardless of the terminal type; thus the problem arose when I attempted to clear the contents of a terminal window. The curses library contains routines to accomplish this task. When I ran into the error shown above, I figured that one of two things was true. Either the library wasn't installed on the system (maybe it had been removed) or the linker just couldn't find it. A quick scan of the system showed that the "missing" library was installed in /usr/local/lib.
oopsy# ls -l /usr/local/lib/libn*
-rwxr-xr-x 1 bin bin 247760 May 1 2001 /usr/local/lib/libncurses++.a
-rw-r--r-- 1 bin bin 453732 May 1 2001 /usr/local/lib/libncurses.a
lrwxrwxrwx 1 root root 15 May 20 2003 /usr/local/lib/libncurses.so -> libncurses.so.5
lrwxrwxrwx 1 root root 17 May 20 2003 /usr/local/lib/libncurses.so.5 -> libncurses.so.5.2
-rw-r--r-- 1 bin bin 338384 May 1 2001 /usr/local/lib/libncurses.so.5.2
-rw-r--r-- 1 bin bin 3459752 May 1 2001 /usr/local/lib/libncurses_g.a
To understand why the linker couldn't find the library, you need to know something about how the linker locates object files in the first place. In short, it uses its own search path much like the shell uses the $PATH variable. By default,
the linker's search path generally includes only /usr/lib. If libraries are installed on your server in other locations, you either need to append their directories to the LD_LIBRARY_PATH variable (which, by default, has no value) for your user accounts or you can amend the default search path using the crle (configure runtime linking environment) command. The crle command which, without arguments, displays the current search path for ld.so.1, indicated that /usr/local/lib was not included (refer to the second line of output below).
oopsy:/var/adm # crle
Configuration file [version 4]: /var/ld/ld.config
Default Library Path (ELF): /usr/lib <== default path
Trusted Directories (ELF): /lib/secure:/usr/lib/secure (system default)
Command line:
crle -c /var/ld/ld.config -l /usr/lib
Additional directories can be added to the linker's search path with the crle command. If you do this, make sure you specify the complete path, including the current directories. Otherwise, your linker will have trouble running even the most innocuous system commands. Most, if not all, system commands make use of shared object files in /usr/lib.
oopsy# crle -l /usr/lib:/usr/local/lib
Note that the path shown above includes the pre-existing as well as the new directories. When you issue a crle command like that shown above, crle will update the linker's configuration file -- /var/ld/ld.config. Unlike most configuration files on Solaris systems, this file is not a straight text file. Display its contents with "od -bc /var/ld/ld.config" if you would like to see what I mean). As a result, it will look odd if you use the cat command to display it or attempt to edit it with vi. Don't. Looking at crle's output after the command to redefine its search path, we see the /usr/local/lib directory has been added.
oopsy:/var/adm # crle
Configuration file [version 4]: /var/ld/ld.config
Default Library Path (ELF): /usr/lib:/usr/local/lib
Trusted Directories (ELF): /lib/secure:/usr/lib/secure (system
default)
Command line:
crle -c /var/ld/ld.config -l /usr/lib:/usr/local/lib
Now, when I go to clear the screen, the command works properly and it should continue to do so through various logins and reboots.
oopsy# clear