[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Linking with installed libtool-constructed library

From: Steve Robbins
Subject: Linking with installed libtool-constructed library
Date: Sun, 28 Jan 2001 05:33:13 -0500
User-agent: Mutt/1.3.12i


I have a project that uses automake & autoconf to build a program.
This program links against several previously-installed libraries.
One of these libraries was built by libtool.

The libtool docs (I'm working with libtool 1.3.5) suggest that one ought to 
link using

        libtool --mode=link gcc -o foo foo.o /usr/local/

(rather than just "gcc ... -lbar").  This allows libtool a chance to 
do special stuff.

So, what's the recommended way of making this happen?  

The library in question is optional, and configure detects its
presence automatically with AC_CHECK_LIB and the like.  But this only
checks whether a program links properly using "-lbar", and does not
give me the pathname of the ".la" file, of course.

I checked the autoconf macro archive <>
but found nothing suitable.  I looked at the libtool mailing list archives
briefly, and didn't find any answer.  I did find someone proposing something
that sounds like a solution:


    The solution I would like to see is to supply AC_CHECK_LTLIB
    macro with libtool.  The macro first looks for installed libtool
    libraries and assign /path/to/ to the appropriate
    variable.  It should fallback to AC_CHECK_LIB compatible mode
    (looks for and exports `-L/path/to` and `-lfoo`), in
    case libtool library is not found.

This person later posted the start of an implementation, 
<> but there was
no discussion that I could see.

What I ended up doing is writing some shell code in "configure" that
filters the "$LIBS" variable, replacing "-lbar" with "/path/to/", if
that file can be found in directories specified by "-L" options.  The 
code is a quick hack, but it works in limited cases (e.g. I only check for
static libs).

The configure snippet is shown below.  Is there a better way?

--- snippet of ---

for x in $LDFLAGS -- $LIBS; do
    case $x in
        -L*) dir=`echo $x | sed 's/^-L//'`
             dirlist="$dirlist $dir"
        -l*) lib=`echo $x | sed 's/^-l//'`
             for dir in $dirlist; do
                if test -r $dir/lib${lib}.a -a -r $dir/lib${lib}.la; then
    if test $proc_libs = yes; then
        newlibs="$newlibs $x"
    elif test $x = --; then



reply via email to

[Prev in Thread] Current Thread [Next in Thread]