LINUX TIPS AND TRICKS --- September 15, 2000

Published by ITworld.com, the IT problem-solving network
http://www.itworld.com/newsletters

*********************************************************************

Shared Libraries Troubleshooting
by Danny Kalev

This week, I will show how to diagnose and solve common problems with 
shared libraries. To easily diagnose a missing shared library, run a 
program (for example, myprog) and if you receive the following error 
message ...

  myprog: can't load library 'lib'

 ... then the runtime linker couldn't find the shared library 'lib'. If 
the physical library file doesn't exist on your machine or it became 
corrupt, you have to (re)install it. If the library exists but the 
runtime linker couldn't find it, you need to recompile your program with 
the appropriate options to indicate the library's location. At the very 
minimum, a runtime linker searches for shared libraries at the /lib and 
/usr/lib directories. If the library isn't located in one of these 
directories, you need to pass special instructions to the runtime linker 
regarding the library's location. Do this by adding the following option 
to the gcc (or g++) command:

  -Ldir

This flag ensures a search of the directory 'dir' in addition to the 
standard directories. The following option ensures that the linker 
(automatically invoked after a successful compilation unless you 
explicitly disable it) also receives the information regarding the 
library's location:

  -Wl,-rpath=dir

Let's parse it: -Wl indicates a linker option. You can pass one or more 
options after the comma. In this example, we pass the option -rpath=dir, 
which instructs the linker to look for the library in the directory 
'dir', too.

--Modifying /etc/ld.so.conf

The file /etc/ld.so.conf contains a list of directories that the runtime 
linker looks at in addition to /lib and /usr/lib. You can add additional 
entries to this file and put the changes into effect by running:

  ldconfig -v

Note, however, that adding unnecessary directories into this file can 
degrade the system's performance. Do not make any changes to ld.so.conf 
unless you know what you're doing.

--Setting LD_LIBRARY_PATH 

So far so good, but what if don't have the program's source files and, 
therefore, can't recompile it? As a last resort, you can set the 
environment variable LD_LIBRARY_PATH. Assigning a colon-separated list 
of directories ensures the runtime linker looks for shared libraries in 
these directories. Again, you should be extremely cautious here. Using 
this variable slows startup time and might cause library version 
mismatches. Never compile any package with this variable set. 
Furthermore, do not set this variable in any user default environment.

Resources

Which is better, static or dynamic linking? 
At compile time, developers can choose static or dynamic linking. 
Which offers better performance?
http://www.sunworld.com/sunworldonline/swol-02-1996/swol-02-perf_p.html

How to avoid potential pitfalls in your Java application development 
Writing enterprise Java apps for Solaris and Windows NT? Here are 10 
common weak points to consider when aiming for cross-platform 
compatibility
http://sw.itworld.com/sunworldonline/swol-11-1998/swol-11-javaapps.html

Linux development: CLI, Emacs, or IDE? 
Joe Barr gets few equivocal answers from leading developers
http://www.linuxworld.com/linuxworld/lw-1999-06/lw-06-vcontrol_1.html

************************************************************************ 

About the author
----------------
Danny Kalev is a system analyst and software engineer with more
than 10 years of experience, specializing in C++ and
object-oriented analysis and design on various platforms including
VMS, DOS, Windows, Unix, and Linux. His technical interests involve
code optimization, networking, and distributed computing. He is
also a member of the ANSI C++ standardization committee and the
author of ANSI/ISO C++ Professional Programmer's Handbook (Que,
1999). Contact him at linuxnl@excite.com.

*********************************************************************

CONTACTS

* For editorial comments, write Andrew Santosusso, Associate Editor, 
Newsletters at: andrew_santosusso@itworld.com
* For advertising information, write Dan Chupka, Account Executive at:
dan_chupka@itworld.com
* For recruitment advertising information, write Jamie Swartz, Eastern
Regional Sales Manager at: jamie_swartz@itworld.com or Paul Duthie,
Western Regional Sales Manager at: paul_duthie@itworld.com
* For all other inquiries, write Jodie Naze, Product Manager,
Newsletters at: jodie_naze@itworld.com

*********************************************************************

Copyright 2000 ITworld.com, Inc., All Rights Reserved. 

http://www.itworld.com
