Hello,
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/libbar.la
(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 <http://research.cys.de/autoconf-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:
<http://mail.gnu.org/pipermail/libtool/1999-July/003653.html>
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/libfoo.la to the appropriate
variable. It should fallback to AC_CHECK_LIB compatible mode
(looks for libfoo.so and exports `-L/path/to` and `-lfoo`), in
case libtool library is not found.
This person later posted the start of an implementation,
<http://mail.gnu.org/pipermail/libtool/1999-July/003719.html> 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/bar.la", 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 configure.in ---
dirlist=
newlibs=
proc_libs=no
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
x=$dir/lib${lib}.la
fi
done
;;
esac
if test $proc_libs = yes; then
newlibs="$newlibs $x"
elif test $x = --; then
proc_libs=yes
fi
done
LIBS=$newlibs
-------------------------------
Thanks,
-Steve