Back: Inter-library Dependencies
Forward: Executing Uninstalled Binaries
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.2 Using Convenience Libraries

To rebuild `libtrim' as a convenience library (see section Creating Convenience Libraries), use the following commands:

$ rm hello *.la
$ ls
hello.c   hello.lo   hello.o   main.c   trim.c   trim.lo   trim.o
$ libtool gcc -o trim.lo
rm -fr .libs/ .libs/libtrim.* .libs/libtrim.*
ar cru .libs/ trim.lo
ranlib .libs/
(cd .libs && rm -f && ln -s ../

Then, rebuild `libhello', with an inter-library dependency on `libtrim' (see section 10.4.1 Inter-library Dependencies), like this:

$ libtool gcc -rpath `pwd`/_inst -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.
rm -fr .libs/libhello.lax
mkdir .libs/libhello.lax
rm -fr .libs/libhello.lax/
mkdir .libs/libhello.lax/
(cd .libs/libhello.lax/ && ar x /tmp/./.libs/
/opt/gcc-lib/hp821/2.7.0/ld -b +h +b /tmp/hello/_inst \
-o .libs/  hello.lo .libs/libhello.lax/
(cd .libs && rm -f && ln -s
(cd .libs && rm -f && ln -s
rm -fr .libs/libhello.lax
mkdir .libs/libhello.lax
rm -fr .libs/libhello.lax/
mkdir .libs/libhello.lax/
(cd .libs/libhello.lax/ && ar x /tmp/hello/./.libs/
ar cru .libs/libhello.a  hello.o  .libs/libhello.lax/
ranlib .libs/libhello.a
rm -fr .libs/libhello.lax .libs/libhello.lax
(cd .libs && rm -f && ln -s ../
$ ls
hello.c    hello.o   trim.c    trim.o
hello.lo   main.c       trim.lo

Compare this to the previous example of building `libhello' and you can see that things are rather different. On HP-UX, partial linking is not known to work, so libtool extracts the objects from the convenience library, and links them directly into `libhello'. That is, `libhello' is comprised of its own objects and the objects in `libtrim'. If `libtrim' had had any dependencies, `libhello' would have inherited them too. This technique is especially useful for grouping source files into subdirectories, even though all of the objects compiled in the subdirectories must eventually reside in a big library: compile the sources in each into a convenience library, and in turn link all of these into a single library which will then contain all of the constituent objects and dependencies of the various convenience libraries.

When you relink the hello executable, notice that `libtrim' is not linked, because the `libtrim' objects are already present in `libhello':

$ 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/ \
-Wl,+b -Wl,/tmp/intro-hello/.libs:/usr/local/lib
creating hello
$ ./hello
Hello, World!

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