Libtool

libtool addresses the same sorts of problems as autoconf. Linking is even less standardised across platforms than compiling. Not all platforms support shared libraries, and the syntaxes for the linkers differ considerably. What libtool does is take a compile or link command as an argument, and run the appropriate platform specific command.

To use libtool, you need to copy several files into your project directory: config.guess, config.sub, install-sh, libtool.m4, ltconfig, ltmain.sh You may download these files and the example The configure.in file needs to use the AM_PROG_LIBTOOL macro. Here's our configure.in:

AC_INIT(configure.in)
AC_SUBST(top_builddir)
AC_PROG_INSTALL
top_builddir=`pwd`
AM_PROG_LIBTOOL
AC_PROG_CXX
AC_OUTPUT(Makefile)

The top_builddir is needed so that the full path to the directory in which the libtool script is installed is known to the configure script.

Now here's the Makefile.in

PROG=libfoo.la
SOURCES=foo.cpp
OBJS=foo.lo
top_builddir=@top_builddir@
LIBTOOL=@LIBTOOL@
CXX=@CXX@
CC=@CC@
INSTALL=@INSTALL@
PREFIX=@prefix@
INCLUDES=-I.
LD_FLAGS=


%.lo:	%.cpp
	$(LIBTOOL) $(CXX) -c $(INCLUDES) $<

%.lo:	%.cc
	$(LIBTOOL) $(CXX) -c $(INCLUDES) $<

$(PROG): $(OBJS)
	$(LIBTOOL) $(CXX) -o $(PROG) $(OBJS) -rpath $(PREFIX)/lib $(LD_FLAGS) 

install:
	$(LIBTOOL) $(INSTALL) -m 755 $(PROG) $(PREFIX)/lib

clean:
	rm -rf .libs *.o *.lo $(PROG)

distclean: clean
	rm -f Makefile config.cache config.log config.status

So what it boils down to is that we prepend libtool to all of the commands in Makefile.in, and we have a libtool based build.

Note that the commands that libtool actually choose could depend on the system. For example,

	$(LIBTOOL) $(CXX) -o $(PROG) $(OBJS) -rpath $(PREFIX)/lib $(LD_FLAGS) 
	
which expands to something like this:
/bin/sh /home/elflord/talk/ex4/libtool c++ -o libfoo.la foo.lo -rpath /usr/local
could actually run a command like this:
ld -Bshareable -o .libs/libhello.so.0.0 foo.lo
libtool absolves the user of the burden of working out how to link on several different platforms. run.