Subject: Re: elf -current .so build/install/rt linker probs
To: None <>
From: John Darrow <>
List: current-users
Date: 04/04/2000 10:35:40
Eric <> wrote:
>On Mon, Apr 03, 2000 at 10:33:00PM -0700, NJ Verenini wrote:
>> I looked at some of the software with the problem (how it built
>> executables), and they all seem to do something like this:
>> gcc .libs/ -o foo foo.c
>> instead of something like
>> gcc -o foo foo.c -L./libs -lfoo
>> Maybe that is part of the problem...
>	Well, looking at the ldd output, it seems that linking the libs in
>using the first method gets the path of the lib included with the name.
>".libs/" instead of "".  What should happen is that
>when the program gets linked it should figure out what the base name of
>the lib is (w/o the path) and the path to it should go in a -Wl,-rpath

The linker is doing exactly what we tell it to, linking in an object
'.libs/' into an executable.  It could be argued that the path
should be stripped from the internal table if the object turns out to be
a shared library (thus resulting in a runtime-type link).  But see below.

>	With the number of problems that I've seen recently because of
>missing -rpath stuff I'm inclined to suggest that a worthy improvement 
>for the compile-time linker would be to automatically add the correct
>path when given a relative path to a library or a -L... argument.
>Especially since so many things don't know about -rpath.
>i.e. gcc -o foo foo.c -L./.libs -lfoo should do what
>     gcc -o foo foo.c -L./.libs -lfoo -Wl,-rpath,./.libs does now.
>(currently, without the -rpath foo won't work correctly)

This is exactly the opposite from what we want to do.

The point is that locations like './.libs' are _temporary_ - they are
used during the build process, and will probably no longer exist once the
program is installed.  We don't want the runtime loader wasting time
looking up directories which don't exist.  (It's for reasons like this
that the -L does _not_ automatically stuff in a runtime path.)

The libraries are eventually (upon install) going to go into a specific
place, e.g. /usr/local/lib.   _This_ is what should go into the -rpath.

In other words, the compile line should be something like this:

gcc -o foo foo.c -L./.libs -lfoo -Wl,-rpath,/usr/local/lib

On both a.out and elf, this will produce an executable which will just
work, without the need of either ldconfig or LD_LIBRARY_PATH.


John Darrow - Senior Technical Specialist               Office: 630/752-5201
Computing Services, Wheaton College, Wheaton, IL 60187  Fax:    630/752-5968
Alphapage:            Pager:  630/316-0707