Back: Linking a Library
Forward: Using Convenience Libraries
FastBack: Executing Uninstalled Binaries
Up: Linking a Library
FastForward: Executing Uninstalled Binaries
Top: Autoconf, Automake, and Libtool
Contents: Table of Contents
Index: Index
About: About this document

10.4.1 Inter-library Dependencies

libtool's inter-library dependency support will use the native implementation if there is one available. If there is no native implementation, or if the native implementation is broken or incomplete, libtool will use an implementation of its own.

To build `libtrim' as a standard Libtool library (see section 10.2 The Libtool Library), as follows:

$ rm hello *.a *.o
$ ls
hello.c   main.c   trim.c
$ libtool gcc -c trim.c
rm -f .libs/trim.lo
gcc -c  -fPIC -DPIC trim.c -o .libs/trim.lo
gcc -c trim.c -o trim.o >/dev/null 2>&1
mv -f .libs/trim.lo trim.lo
$ libtool gcc -rpath /usr/local/lib -o trim.lo
rm -fr .libs/ .libs/libtrim.* .libs/libtrim.*
/opt/gcc-lib/hp821/2.7.0/ld -b +h +b /usr/local/lib \
-o .libs/  trim.lo
(cd .libs && rm -f && ln -s
(cd .libs && rm -f && ln -s
ar cru .libs/libtrim.a  trim.o
ranlib .libs/libtrim.a
(cd .libs && rm -f && ln -s ../

When you build `libhello', you can specify the libraries it depends on at the command line, like so:

$ libtool gcc -c hello.c
rm -f .libs/hello.lo
gcc -c  -fPIC -DPIC hello.c -o .libs/hello.lo
gcc -c hello.c -o hello.o >/dev/null 2>&1
mv -f .libs/hello.lo hello.lo
$ libtool gcc -rpath /usr/local/lib -o hello.lo
rm -fr .libs/ .libs/libhello.* .libs/libhello.*

*** Warning: inter-library dependencies are not known to be supported.
*** All declared inter-library dependencies are being dropped.
*** The inter-library dependencies that have been dropped here will be
*** automatically added whenever a program is linked with this library
*** or is declared to -dlopen it.
/opt/gcc-lib/hp821/2.7.0/ld -b +h +b /usr/local/lib \
-o .libs/  hello.lo
(cd .libs && rm -f && ln -s
(cd .libs && rm -f && ln -s
ar cru .libs/libhello.a  hello.o
ranlib .libs/libhello.a
(cd .libs && rm -f && ln -s ../
$ ls
hello.c    hello.o   trim.c   trim.o
hello.lo   main.c       trim.lo

Although, on HP-UX, libtool warns that it doesn't know how to use the native inter-library dependency implementation, it will track the dependencies and make sure they are added to the final link line, so that you only need to specify the libraries that you use directly.

Now, you can rebuild `hello' exactly as in the earlier example (see section 10.3 Linking an Executable), as in:

$ libtool gcc -o hello main.c
libtool: link: warning: this platform does not like uninstalled
libtool: link: warning: shared libraries
libtool: link: hello will be relinked during installation
gcc -o .libs/hello main.c /tmp/intro-hello/.libs/ \
/tmp/intro-hello/.libs/ \
-Wl,+b -Wl,/tmp/intro-hello/.libs:/usr/local/lib
creating hello
$ ./hello
Hello, World!

Notice that even though you only specified the `' library at the command line, libtool remembers that `' depends on `' and links that library too.

You can also link a static executable, and the dependencies are handled similarly:

$ libtool gcc -o hello-again -static main.c
gcc -o hello main.c ./.libs/libhello.a /tmp/intro-hello/.libs/libtrim.a
$ ./hello-again
Hello, World!

For your own projects, provided that you use libtool, and that you specify the libraries you wish to link using the `.la' pseudo-libraries, these dependencies can be nested as deeply as you like. You can also register dependencies on native libraries, though you will of course need to specify any dependencies that the native library itself has at the same time.

This document was generated by Gary V. Vaughan on February, 8 2006 using texi2html