\input texinfo @c -*-texinfo-*-@c %**start of header@setfilename libtool.info@settitle Libtool@c For double-sided printing, uncomment:@c @setchapternewpage odd@c %**end of header@include version.texi@set BUGADDR the libtool bug reporting address @email{bug-libtool@@gnu.org}@set MAILLIST the libtool mailing list @email{libtool@@gnu.org}@set objdir .libs@dircategory GNU programming tools@direntry* Libtool: (libtool). Generic shared library support script.@end direntry@dircategory Individual utilities@direntry* libtoolize: (libtool)Invoking libtoolize. Adding libtool support.@end direntry@ifnottexThis file documents GNU Libtool @value{VERSION}Copyright (C) 1996-2003, 2005 Free Software Foundation, Inc.Permission is granted to copy, distribute and/or modify this documentunder the terms of the GNU Free Documentation License, Version 1.1or any later version published by the Free Software Foundation;with the no Invariant Sections, with no Front-Cover Texts,and with no Back-Cover Texts. A copy of the license is included inthe section entitled "GNU Free Documentation License".@ignorePermission is granted to process this file through TeX and print theresults, provided the printed document carries copying permission noticeidentical to this one except for the removal of this paragraph@end ignore@end ifnottex@titlepage@title GNU Libtool@subtitle For version @value{VERSION}, @value{UPDATED}@author Gordon Matzigkeit@author Alexandre Oliva@author Thomas Tanner@author Gary V. Vaughan@page@vskip 0pt plus 1filllCopyright @copyright{} 1996-2003 Free Software Foundation, Inc.Permission is granted to copy, distribute and/or modify this documentunder the terms of the GNU Free Documentation License, Version 1.1or any later version published by the Free Software Foundation;with the no Invariant Sections, with no Front-Cover Texts,and with no Back-Cover Texts. A copy of the license is included inthe section entitled "GNU Free Documentation License".@end titlepage@c Put everything in one index (arbitrarily chosen to be the concept index).@syncodeindex vr cp@syncodeindex fn cp@syncodeindex tp cp@synindex pg cp@ifnottex@node Top, Introduction, (dir), (dir)@comment node-name, next, previous, up@top Shared library support for GNUThis file documents GNU Libtool, a script that allows package developersto provide generic shared library support. This edition documentsversion @value{VERSION}.@xref{Reporting bugs}, for information on how to report problems withlibtool.@menu* Introduction:: What the heck is libtool?* Libtool paradigm:: How libtool's view of libraries is different.* Using libtool:: Example of using libtool to build libraries.* Invoking libtool:: Running the @code{libtool} script.* Integrating libtool:: Using libtool in your own packages.* Versioning:: Using library interface versions.* Library tips:: Tips for library interface design.* Inter-library dependencies:: Libraries that depend on other libraries.* Dlopened modules:: @code{dlopen}ing libtool-created libraries.* Using libltdl:: Libtool's portable @code{dlopen} wrapper library.* Other languages:: Using libtool without a C compiler.* Troubleshooting:: When libtool doesn't work as advertised.* Maintaining:: Information used by the libtool maintainer.* GNU Free Documentation License:: License for this manual.* Index:: Full index.@detailmenu --- The Detailed Node Listing ---Introduction* Motivation:: Why does GNU need a libtool?* Issues:: The problems that need to be addressed.* Other implementations:: How other people have solved these issues.* Postmortem:: Learning from past difficulties.Using libtool* Creating object files:: Compiling object files for libraries.* Linking libraries:: Creating libraries from object files.* Linking executables:: Linking object files against libtool libraries.* Debugging executables:: Running GDB on libtool-generated programs.* Installing libraries:: Making libraries available to users.* Installing executables:: Making programs available to users.* Static libraries:: When shared libraries are not wanted.Invoking @code{libtool}* Compile mode:: Creating library object files.* Link mode:: Generating executables and libraries.* Execute mode:: Debugging libtool-generated programs.* Install mode:: Making libraries and executables public.* Finish mode:: Completing a library installation.* Uninstall mode:: Removing installed executables and libraries.* Clean mode:: Removing uninstalled executables and libraries.Integrating libtool with your package* Makefile rules:: Writing @file{Makefile} rules for libtool.* Using Automake:: Automatically supporting libtool.* Configuring:: Configuring libtool for a host system.* Distributing:: What files to distribute with your package.* Static-only libraries:: Sometimes shared libraries are just a pain.Configuring libtool* AC_PROG_LIBTOOL:: Configuring @code{libtool} in @file{configure.in}.Including libtool in your package* Invoking libtoolize:: @code{libtoolize} command line options.* Autoconf .o macros:: Autoconf macros that set object file names.Library interface versions* Interfaces:: What are library interfaces?* Libtool versioning:: Libtool's versioning system.* Updating version info:: Changing version information before releases.* Release numbers:: Breaking binary compatibility for aesthetics.Tips for interface design* C header files:: How to write portable include files.Dlopened modules* Building modules:: Creating dlopenable objects and libraries.* Dlpreopening:: Dlopening that works on static platforms.* Finding the dlname:: Choosing the right file to @code{dlopen}.* Dlopen issues:: Unresolved problems that need your attention.Using libltdl* Libltdl interface:: How to use libltdl in your programs.* Modules for libltdl:: Creating modules that can be @code{dlopen}ed.* Thread Safety in libltdl:: Registering callbacks for multi-thread safety.* User defined module data:: Associating data with loaded modules.* Module loaders for libltdl:: Creating user defined module loaders.* Distributing libltdl:: How to distribute libltdl with your package.Using libtool with other languages* C++ libraries::Troubleshooting* Libtool test suite:: Libtool's self-tests.* Reporting bugs:: How to report problems with libtool.The libtool test suite* Test descriptions:: The contents of the test suite.* When tests fail:: What to do when a test fails.Maintenance notes for libtool* New ports:: How to port libtool to new systems.* Tested platforms:: When libtool was last tested.* Platform quirks:: Information about different library systems.* libtool script contents:: Configuration information that libtool uses.* Cheap tricks:: Making libtool maintainership easier.Porting libtool to new systems* Information sources:: Where to find relevant documentation* Porting inter-library dependencies:: Implementation details explainedPlatform quirks* References:: Finding more information.* Compilers:: Creating object files from source files.* Reloadable objects:: Binding object files together.* Multiple dependencies:: Removing duplicate dependent libraries.* Archivers:: Programs that create static archives.@end detailmenu@end menu@end ifnottex@node Introduction@chapter IntroductionIn the past, if a source code package developer wanted to take advantageof the power of shared libraries, he needed to write custom support codefor each platform on which his package ran. He also had to design aconfiguration interface so that the package installer could choose what sort oflibraries were built.GNU Libtool simplifies the developer's job by encapsulating both theplatform-specific dependencies, and the user interface, in a singlescript. GNU Libtool is designed so that the complete functionality ofeach host type is available via a generic interface, but nasty quirksare hidden from the programmer.GNU Libtool's consistent interface is reassuring@dots{} users don't needto read obscure documentation in order to have their favorite sourcepackage build shared libraries. They just run your package@code{configure} script (or equivalent), and libtool does all the dirtywork.There are several examples throughout this document. All assume thesame environment: we want to build a library, @file{libhello}, in ageneric way.@file{libhello} could be a shared library, a static library, orboth@dots{} whatever is available on the host system, as long as libtoolhas been ported to it.This chapter explains the original design philosophy of libtool. Feelfree to skip to the next chapter, unless you are interested in history,or want to write code to extend libtool in a consistent way.@menu* Motivation:: Why does GNU need a libtool?* Issues:: The problems that need to be addressed.* Other implementations:: How other people have solved these issues.* Postmortem:: Learning from past difficulties.@end menu@node Motivation@section Motivation for writing libtool@cindex motivation for writing libtool@cindex design philosophySince early 1995, several different GNU developers have recognized theimportance of having shared library support for their packages. Theprimary motivation for such a change is to encourage modularity andreuse of code (both conceptually and physically) in GNU programs.Such a demand means that the way libraries are built in GNU packagesneeds to be general, to allow for any library type the package installermight want. The problem is compounded by the absence of a standardprocedure for creating shared libraries on different platforms.The following sections outline the major issues facing shared librarysupport in GNU, and how shared library support could be standardizedwith libtool.@cindex specifications for libtool@cindex libtool specificationsThe following specifications were used in developing and evaluating thissystem:@enumerate@itemThe system must be as elegant as possible.@itemThe system must be fully integrated with the GNU Autoconf and Automakeutilities, so that it will be easy for GNU maintainers to use. However,the system must not require these tools, so that it can be used bynon-GNU packages.@itemPortability to other (non-GNU) architectures and tools is desirable.@end enumerate@node Issues@section Implementation issues@cindex tricky design issues@cindex design issuesThe following issues need to be addressed in any reusable shared librarysystem, specifically libtool:@enumerate@itemThe package installer should be able to control what sort of librariesare built.@itemIt can be tricky to run dynamically linked programs whose libraries havenot yet been installed. @code{LD_LIBRARY_PATH} must be set properly (ifit is supported), or programs fail to run.@itemThe system must operate consistently even on hosts which don't supportshared libraries.@itemThe commands required to build shared libraries may differ wildly fromhost to host. These need to be determined at configure time ina consistent way.@itemIt is not always obvious with which suffix a shared library should beinstalled. This makes it difficult for @file{Makefile} rules, since theygenerally assume that file names are the same from host to host.@itemThe system needs a simple library version number abstraction, so thatshared libraries can be upgraded in place. The programmer should beinformed how to design the interfaces to the library to maximize binarycompatibility.@itemThe install @file{Makefile} target should warn the package installer to setthe proper environment variables (@code{LD_LIBRARY_PATH} or equivalent),or run @code{ldconfig}.@end enumerate@node Other implementations@section Other implementationsEven before libtool was developed, many free software packages built andinstalled their own shared libraries. At first, these packages wereexamined to avoid reinventing existing features.Now it is clear that none of these packages have documented the detailsof shared library systems that libtool requires. So, other packageshave been more or less abandoned as influences.@node Postmortem@section A postmortem analysis of other implementations@cindex other implementations, flaws in@cindex reusability of library systemsIn all fairness, each of the implementations that were examined do thejob that they were intended to do, for a number of different hostsystems. However, none of these solutions seem to function well as ageneralized, reusable component.@cindex complexity of library systemsMost were too complex to use (much less modify) without understandingexactly what the implementation does, and they were generally notdocumented.The main difficulty is that different vendors have different views ofwhat libraries are, and none of the packages which were examined seemedto be confident enough to settle on a single paradigm that just@emph{works}.Ideally, libtool would be a standard that would be implemented as seriesof extensions and modifications to existing library systems to make themwork consistently. However, it is not an easy task to convinceoperating system developers to mend their evil ways, and people want tobuild shared libraries right now, even on buggy, broken, confusedoperating systems.For this reason, libtool was designed as an independent shell script.It isolates the problems and inconsistencies in library building thatplague @file{Makefile} writers by wrapping the compiler suite ondifferent platforms with a consistent, powerful interface.With luck, libtool will be useful to and used by the GNU community, andthat the lessons that were learned in writing it will be taken up bydesigners of future library systems.@node Libtool paradigm@chapter The libtool paradigmAt first, libtool was designed to support an arbitrary number of libraryobject types. After libtool was ported to more platforms, a newparadigm gradually developed for describing the relationship betweenlibraries and programs.@cindex definition of libraries@cindex libraries, definition ofIn summary, ``libraries are programs with multiple entry points, andmore formally defined interfaces.''Version 0.7 of libtool was a complete redesign and rewrite of libtool toreflect this new paradigm. So far, it has proved to be successful:libtool is simpler and more useful than before.The best way to introduce the libtool paradigm is to contrast it withthe paradigm of existing library systems, with examples from each. Itis a new way of thinking, so it may take a little time to absorb, butwhen you understand it, the world becomes simpler.@node Using libtool@chapter Using libtool@cindex examples of using libtool@cindex libtool examplesIt makes little sense to talk about using libtool in your own packagesuntil you have seen how it makes your life simpler. The examples inthis chapter introduce the main features of libtool by comparing thestandard library building procedure to libtool's operation on twodifferent platforms:@table @samp@item a23An Ultrix 4.2 platform with only static libraries.@item burgerA NetBSD/i386 1.2 platform with shared libraries.@end tableYou can follow these examples on your own platform, using thepreconfigured libtool script that was installed with libtool(@pxref{Configuring}).Source files for the following examples are taken from the @file{demo}subdirectory of the libtool distribution. Assume that we are building alibrary, @file{libhello}, out of the files @file{foo.c} and@file{hello.c}.Note that the @file{foo.c} source file uses the @code{cos} math libraryfunction, which is usually found in the standalone math library, and notthe C library (@pxref{Trig Functions, , Trigonometric Functions, libc,The GNU C Library Reference Manual}). So, we need to add @kbd{-lm} tothe end of the link line whenever we link @file{foo.o} or @file{foo.lo}into an executable or a library (@pxref{Inter-library dependencies}).The same rule applies whenever you use functions that don't appear inthe standard C library@dots{} you need to add the appropriate@kbd{-l@var{name}} flag to the end of the link line when you linkagainst those objects.After we have built that library, we want to create a program by linking@file{main.o} against @file{libhello}.@menu* Creating object files:: Compiling object files for libraries.* Linking libraries:: Creating libraries from object files.* Linking executables:: Linking object files against libtool libraries.* Debugging executables:: Running GDB on libtool-generated programs.* Installing libraries:: Making libraries available to users.* Installing executables:: Making programs available to users.* Static libraries:: When shared libraries are not wanted.@end menu@node Creating object files@section Creating object files@cindex compiling object files@cindex object files, compilingTo create an object file from a source file, the compiler is invokedwith the `-c' flag (and any other desired flags):@exampleburger$ @kbd{gcc -g -O -c main.c}burger$@end exampleThe above compiler command produces an object file, @file{main.o}, fromthe source file @file{main.c}.For most library systems, creating object files that become part of astatic library is as simple as creating object files that are linked toform an executable:@exampleburger$ @kbd{gcc -g -O -c foo.c}burger$ @kbd{gcc -g -O -c hello.c}burger$@end example@cindex position-independent code@cindex PIC (position-independent code)Shared libraries, however, may only be built from@dfn{position-independent code} (PIC). So, special flags must be passedto the compiler to tell it to generate PIC rather than the standardposition-dependent code.@cindex library object file@cindex @samp{.lo} files@cindex object files, librarySince this is a library implementation detail, libtool hides thecomplexity of PIC compiler flags by using separate library object files(which end in @samp{.lo} instead of @samp{.o}). On systems without sharedlibraries (or without special PIC compiler flags), these library objectfiles are identical to ``standard'' object files.To create library object files for @file{foo.c} and @file{hello.c},simply invoke libtool with the standard compilation command asarguments (@pxref{Compile mode}):@examplea23$ @kbd{libtool --mode=compile gcc -g -O -c foo.c}gcc -g -O -c foo.cecho timestamp > foo.loa23$ @kbd{libtool --mode=compile gcc -g -O -c hello.c}gcc -g -O -c hello.cecho timestamp > hello.loa23$@end exampleNote that libtool creates two files for each invocation. The @samp{.lo}file is a library object, which may be built into a shared library, andthe @samp{.o} file is a standard object file. On @samp{a23}, thelibrary objects are just timestamps, because only static libraries aresupported.On shared library systems, libtool automatically inserts the PICgeneration flags into the compilation command, so that the libraryobject and the standard object differ:@exampleburger$ @kbd{libtool --mode=compile gcc -g -O -c foo.c}gcc -g -O -c -fPIC -DPIC foo.cmv -f foo.o foo.logcc -g -O -c foo.c >/dev/null 2>&1burger$ @kbd{libtool --mode=compile gcc -g -O -c hello.c}gcc -g -O -c -fPIC -DPIC hello.cmv -f hello.o hello.logcc -g -O -c hello.c >/dev/null 2>&1burger$@end exampleNotice that the second run of GCC has its output discarded. This isdone so that compiler warnings aren't annoyingly duplicated.@node Linking libraries@section Linking libraries@pindex arWithout libtool, the programmer would invoke the @code{ar} command tocreate a static library:@exampleburger$ @kbd{ar cru libhello.a hello.o foo.o}burger$@end example@pindex ranlibBut of course, that would be too simple, so many systems require thatyou run the @code{ranlib} command on the resulting library (to give itbetter karma, or something):@exampleburger$ @kbd{ranlib libhello.a}burger$@end exampleIt seems more natural to use the C compiler for this task, givenlibtool's ``libraries are programs'' approach. So, on platforms withoutshared libraries, libtool simply acts as a wrapper for the system@code{ar} (and possibly @code{ranlib}) commands.@cindex libtool libraries@cindex @samp{.la} filesAgain, the libtool library name differs from the standard name (it has a@samp{.la} suffix instead of a @samp{.a} suffix). The arguments to libtool arethe same ones you would use to produce an executable named@file{libhello.la} with your compiler (@pxref{Link mode}):@examplea23$ @kbd{libtool --mode=link gcc -g -O -o libhello.la foo.o hello.o}libtool: cannot build libtool library `libhello.la' from non-libtool \objectsa23$@end exampleAha! Libtool caught a common error@dots{} trying to build a libraryfrom standard objects instead of library objects. This doesn't matterfor static libraries, but on shared library systems, it is of greatimportance.So, let's try again, this time with the library object files. Rememberalso that we need to add @kbd{-lm} to the link command line because@file{foo.c} uses the @code{cos} math library function (@pxref{Usinglibtool}).Another complication in building shared libraries is that we need tospecify the path to the directory in which they (eventually) will beinstalled (in this case, @file{/usr/local/lib})@footnote{If you don'tspecify an @code{rpath}, then libtool builds a libtool conveniencearchive, not a shared library (@pxref{Static libraries}).}:@examplea23$ @kbd{libtool --mode=link gcc -g -O -o libhello.la foo.lo hello.lo \-rpath /usr/local/lib -lm}mkdir @value{objdir}ar cru @value{objdir}/libhello.a foo.o hello.oranlib @value{objdir}/libhello.acreating libhello.laa23$@end exampleNow, let's try the same trick on the shared library platform:@exampleburger$ @kbd{libtool --mode=link gcc -g -O -o libhello.la foo.lo hello.lo \-rpath /usr/local/lib -lm}mkdir @value{objdir}ld -Bshareable -o @value{objdir}/libhello.so.0.0 foo.lo hello.lo -lmar cru @value{objdir}/libhello.a foo.o hello.oranlib @value{objdir}/libhello.acreating libhello.laburger$@end exampleNow that's significantly cooler@dots{} libtool just ran an obscure@code{ld} command to create a shared library, as well as the staticlibrary.@cindex @file{@value{objdir}} subdirectoryNote how libtool creates extra files in the @file{@value{objdir}}subdirectory, rather than the current directory. This feature is tomake it easier to clean up the build directory, and to help ensure thatother programs fail horribly if you accidentally forget to use libtoolwhen you should.@node Linking executables@section Linking executables@cindex linking against installed librariesIf you choose at this point to @dfn{install} the library (put it in apermanent location) before linking executables against it, then youdon't need to use libtool to do the linking. Simply use the appropriate@samp{-L} and @samp{-l} flags to specify the library's location.@cindex buggy system linkersSome system linkers insist on encoding the full directory name of eachshared library in the resulting executable. Libtool has to work aroundthis misfeature by special magic to ensure that only permanent directorynames are put into installed executables.@cindex security problems with buggy linkers@cindex bugs, subtle ones caused by buggy linkersThe importance of this bug must not be overlooked: it won't causeprograms to crash in obvious ways. It creates a security hole,and possibly even worse, if you are modifying the library source codeafter you have installed the package, you will change the behaviour ofthe installed programs!So, if you want to link programs against the library before you installit, you must use libtool to do the linking.@cindex linking against uninstalled librariesHere's the old way of linking against an uninstalled library:@exampleburger$ @kbd{gcc -g -O -o hell.old main.o libhello.a -lm}burger$@end exampleLibtool's way is almost the same@footnote{However, you should avoid using@samp{-L} or @samp{-l} flags to link against an uninstalled libtoollibrary. Just specify the relative path to the @samp{.la} file, such as@file{../intl/libintl.la}. This is a design decision to eliminate anyambiguity when linking against uninstalled shared libraries.}(@pxref{Link mode}):@examplea23$ @kbd{libtool --mode=link gcc -g -O -o hell main.o libhello.la -lm}gcc -g -O -o hell main.o ./@value{objdir}/libhello.a -lma23$@end exampleThat looks too simple to be true. All libtool did was transform@file{libhello.la} to @file{./@value{objdir}/libhello.a}, but rememberthat @samp{a23} has no shared libraries.On @samp{burger} the situation is different:@exampleburger$ @kbd{libtool --mode=link gcc -g -O -o hell main.o libhello.la -lm}gcc -g -O -o @value{objdir}/hell main.o -L./@value{objdir} -R/usr/local/lib -lhello -lmcreating hellburger$@end example@cindex linking with installed libtool librariesNow assume @file{libhello.la} had already been installed, and you wantto link a new program with it. You could figure out where it lives byyourself, then run:@exampleburger$ @kbd{gcc -g -O -o test test.o -L/usr/local/lib -lhello}@end exampleHowever, unless @file{/usr/local/lib} is in the standard library searchpath, you won't be able to run @code{test}. However, if you use libtoolto link the already-installed libtool library, it will do The RightThing (TM) for you:@exampleburger$ @kbd{libtool --mode=link gcc -g -O -o test \test.o /usr/local/lib/libhello.la}gcc -g -O -o @value{objdir}/test test.o -Wl,--rpath-Wl,/usr/local/lib /usr/local/lib/libhello.a -lmcreating testburger$@end exampleNote that libtool added the necessary run-time path flag, as well as@samp{-lm}, the library libhello.la depended upon. Nice, huh?Since libtool created a wrapper script, you should use libtool toinstall it and debug it too. However, since the program does not dependon any uninstalled libtool library, it is probably usable even withoutthe wrapper script. Libtool could probably be made smarter to avoid thecreation of the wrapper script in this case, but this is left as anexercise for the reader.@cindex wrapper scripts for programs@cindex program wrapper scriptsNotice that the executable, @code{hell}, was actually created in the@file{@value{objdir}} subdirectory. Then, a wrapper script was createdin the current directory.On NetBSD 1.2, libtool encodes the installation directory of@file{libhello}, by using the @samp{-R/usr/local/lib} compiler flag.Then, the wrapper script guarantees that the executable finds thecorrect shared library (the one in @file{./@value{objdir}}) until it isproperly installed.Let's compare the two different programs:@exampleburger$ @kbd{time ./hell.old}Welcome to GNU Hell!** This is not GNU Hello. There is no built-in mail reader. **0.21 real 0.02 user 0.08 sysburger$ @kbd{time ./hell}Welcome to GNU Hell!** This is not GNU Hello. There is no built-in mail reader. **0.63 real 0.09 user 0.59 sysburger$@end exampleThe wrapper script takes significantly longer to execute, but at leastthe results are correct, even though the shared library hasn't beeninstalled yet.So, what about all the space savings that shared libraries are supposedto yield?@exampleburger$ @kbd{ls -l hell.old libhello.a}-rwxr-xr-x 1 gord gord 15481 Nov 14 12:11 hell.old-rw-r--r-- 1 gord gord 4274 Nov 13 18:02 libhello.aburger$ @kbd{ls -l @value{objdir}/hell @value{objdir}/libhello.*}-rwxr-xr-x 1 gord gord 11647 Nov 14 12:10 @value{objdir}/hell-rw-r--r-- 1 gord gord 4274 Nov 13 18:44 @value{objdir}/libhello.a-rwxr-xr-x 1 gord gord 12205 Nov 13 18:44 @value{objdir}/libhello.so.0.0burger$@end exampleWell, that sucks. Maybe I should just scrap this project and take upbasket weaving.Actually, it just proves an important point: shared libraries incuroverhead because of their (relative) complexity. In this situation, theprice of being dynamic is eight kilobytes, and the payoff is about fourkilobytes. So, having a shared @file{libhello} won't be an advantageuntil we link it against at least a few more programs.@node Debugging executables@section Debugging executablesIf @file{hell} was a complicated program, you would certainly want totest and debug it before installing it on your system. In the abovesection, you saw how the libtool wrapper script makes it possible to runthe program directly, but unfortunately, this mechanism interferes withthe debugger:@exampleburger$ @kbd{gdb hell}GDB is free software and you are welcome to distribute copies of itunder certain conditions; type "show copying" to see the conditions.There is no warranty for GDB; type "show warranty" for details.GDB 4.16 (i386-unknown-netbsd), (C) 1996 Free Software Foundation, Inc."hell": not in executable format: File format not recognized(gdb) @kbd{quit}burger$@end exampleSad. It doesn't work because GDB doesn't know where the executablelives. So, let's try again, by invoking GDB directly on the executable:@exampleburger$ @kbd{gdb @value{objdir}/hell}trick:/home/src/libtool/demo$ gdb .libs/hellGDB is free software and you are welcome to distribute copies of itunder certain conditions; type "show copying" to see the conditions.There is no warranty for GDB; type "show warranty" for details.GDB 4.16 (i386-unknown-netbsd), (C) 1996 Free Software Foundation, Inc.(gdb) @kbd{break main}Breakpoint 1 at 0x8048547: file main.c, line 29.(gdb) @kbd{run}Starting program: /home/src/libtool/demo/.libs/hell/home/src/libtool/demo/.libs/hell: can't load library 'libhello.so.2'Program exited with code 020.(gdb) @kbd{quit}burger$@end exampleArgh. Now GDB complains because it cannot find the shared library that@file{hell} is linked against. So, we must use libtool in order toproperly set the library path and run the debugger. Fortunately, we canforget all about the @file{@value{objdir}} directory, and just run it onthe executable wrapper (@pxref{Execute mode}):@exampleburger$ @kbd{libtool --mode=execute gdb hell}GDB is free software and you are welcome to distribute copies of itunder certain conditions; type "show copying" to see the conditions.There is no warranty for GDB; type "show warranty" for details.GDB 4.16 (i386-unknown-netbsd), (C) 1996 Free Software Foundation, Inc.(gdb) @kbd{break main}Breakpoint 1 at 0x8048547: file main.c, line 29.(gdb) @kbd{run}Starting program: /home/src/libtool/demo/.libs/hellBreakpoint 1, main (argc=1, argv=0xbffffc40) at main.c:2929 printf ("Welcome to GNU Hell!\n");(gdb) @kbd{quit}The program is running. Quit anyway (and kill it)? (y or n) @kbd{y}burger$@end example@node Installing libraries@section Installing libraries@pindex stripInstalling libraries on a non-libtool system is quitestraightforward@dots{} just copy them into place:@footnote{Don'taccidentally strip the libraries, though, or they will be unusable.}@pindex su@exampleburger$ @kbd{su}Password: @kbd{********}burger# @kbd{cp libhello.a /usr/local/lib/libhello.a}burger#@end exampleOops, don't forget the @code{ranlib} command:@exampleburger# @kbd{ranlib /usr/local/lib/libhello.a}burger#@end example@pindex installLibtool installation is quite simple, as well. Just use the@code{install} or @code{cp} command that you normally would(@pxref{Install mode}):@examplea23# @kbd{libtool --mode=install cp libhello.la /usr/local/lib/libhello.la}cp libhello.la /usr/local/lib/libhello.lacp @value{objdir}/libhello.a /usr/local/lib/libhello.aranlib /usr/local/lib/libhello.aa23#@end exampleNote that the libtool library @file{libhello.la} is also installed, tohelp libtool with uninstallation (@pxref{Uninstall mode}) and linking(@pxref{Linking executables}) and to help programs with dlopening(@pxref{Dlopened modules}).Here is the shared library example:@exampleburger# @kbd{libtool --mode=install install -c libhello.la \/usr/local/lib/libhello.la}install -c @value{objdir}/libhello.so.0.0 /usr/local/lib/libhello.so.0.0install -c libhello.la /usr/local/lib/libhello.lainstall -c @value{objdir}/libhello.a /usr/local/lib/libhello.aranlib /usr/local/lib/libhello.aburger#@end example@cindex stripping libraries@cindex libraries, strippingIt is safe to specify the @samp{-s} (strip symbols) flag if you use aBSD-compatible install program when installing libraries.Libtool will either ignore the @samp{-s} flag, or will run a programthat will strip only debugging and compiler symbols from the library.Once the libraries have been put in place, there may be some additionalconfiguration that you need to do before using them. First, you mustmake sure that where the library is installed actually agrees with the@samp{-rpath} flag you used to build it.@cindex postinstallation@cindex installation, finishing@cindex libraries, finishing installationThen, running @samp{libtool -n --mode=finish @var{libdir}} can give youfurther hints on what to do (@pxref{Finish mode}):@exampleburger# @kbd{libtool -n --mode=finish /usr/local/lib}PATH="$PATH:/sbin" ldconfig -m /usr/local/lib-----------------------------------------------------------------Libraries have been installed in:/usr/local/libTo link against installed libraries in a given directory, LIBDIR,you must use the `-LLIBDIR' flag during linking.You will also need to do one of the following:- add LIBDIR to the `LD_LIBRARY_PATH' environment variableduring execution- add LIBDIR to the `LD_RUN_PATH' environment variableduring linking- use the `-RLIBDIR' linker flagSee any operating system documentation about shared libraries formore information, such as the ld and ld.so manual pages.-----------------------------------------------------------------burger#@end exampleAfter you have completed these steps, you can go on to begin using theinstalled libraries. You may also install any executables that dependon libraries you created.@node Installing executables@section Installing executablesIf you used libtool to link any executables against uninstalled libtoollibraries (@pxref{Linking executables}), you need to use libtool toinstall the executables after the libraries have been installed(@pxref{Installing libraries}).So, for our Ultrix example, we would run:@examplea23# libtool install -c hell /usr/local/bin/hellinstall -c hell /usr/local/bin/hella23#@end exampleOn shared library systems, libtool just ignores the wrapper script andinstalls the correct binary:@exampleburger# libtool install -c hell /usr/local/bin/hellinstall -c @value{objdir}/hell /usr/local/bin/hellburger#@end example@node Static libraries@section Linking static libraries@cindex static linking@cindex convenience librariesWhy return to @code{ar} and @code{ranlib} silliness when you've had ataste of libtool? Well, sometimes it is desirable to create a staticarchive that can never be shared. The most frequent case is when youhave a set of object files that you use to build several differentprograms. You can create a ``convenience library'' out of thoseobjects, and link programs with the library, instead of listing allobject files for every program. This technique is often used toovercome GNU automake's lack of support for linking object files builtfrom sources in other directories, because it supports linking withlibraries from other directories. This limitation applies to GNUautomake up to release 1.4; newer releases should support sources inother directories.If you just want to link this convenience library into programs, thenyou could just ignore libtool entirely, and use the old @code{ar} and@code{ranlib} commands (or the corresponding GNU automake@samp{_LIBRARIES} rules). You can even install a convenience library(but you probably don't want to) using libtool:@exampleburger$ @kbd{libtool --mode=install ./install-sh -c libhello.a \/local/lib/libhello.a}./install-sh -c libhello.a /local/lib/libhello.aranlib /local/lib/libhello.aburger$@end exampleUsing libtool for static library installation protects your library frombeing accidentally stripped (if the installer used the @samp{-s} flag),as well as automatically running the correct @code{ranlib} command.But libtool libraries are more than just collections of object files:they can also carry library dependency information, which old archivesdo not. If you want to create a libtool static convenience library, youcan omit the @samp{-rpath} flag and use @samp{-static} to indicate thatyou're only interested in a static library. When you link a programwith such a library, libtool will actually link all object files anddependency libraries into the program.If you omit both @samp{-rpath} and @samp{-static}, libtool will create aconvenience library that can be used to create other libtoollibraries, even shared ones. Just like in the static case, the librarybehaves as an alias to a set of object files and dependency libraries,but in this case the object files are suitable for inclusion in sharedlibraries. But be careful not to link a single convenience library,directly or indirectly, into a single program or library, otherwise youmay get errors about symbol redefinitions.When GNU automake is used, you should use @code{noinst_LTLIBRARIES}instead of @code{lib_LTLIBRARIES} for convenience libraries, so thatthe @samp{-rpath} option is not passed when they are linked.As a rule of thumb, link a libtool convenience library into at most onelibtool library, and never into a program, and link libtool staticconvenience libraries only into programs, and only if you need to carrylibrary dependency information to the user of the static conveniencelibrary.@cindex standalone binariesAnother common situation where static linking is desirable is increating a standalone binary. Use libtool to do the linking and add the@samp{-all-static} flag.@node Invoking libtool@chapter Invoking @code{libtool}@pindex libtool@cindex libtool command options@cindex options, libtool command@cindex command options, libtoolThe @code{libtool} program has the following synopsis:@examplelibtool [@var{option}]@dots{} [@var{mode-arg}]@dots{}@end example@noindentand accepts the following options:@table @samp@item --configDisplay libtool configuration variables and exit.@item --debugDump a trace of shell script execution to standard output. Thisproduces a lot of output, so you may wish to pipe it to @code{less} (or@code{more}) or redirect to a file.@item -n@itemx --dry-runDon't create, modify, or delete any files, just show what commands wouldbe executed by libtool.@item --featuresDisplay basic configuration options. This provides a way for packagesto determine whether shared or static libraries will be built.@item --preserve-dup-depsDo not remove duplicate dependencies in libraries. When building packageswith static libraries, the libraries may depend circularly on each other(shared libs can too, but for those it doesn't matter), so there aresituations, where -la -lb -la is required, and the second -la may not bestripped or the link will fail. In cases where these duplications arerequired, this option will preserve them, only stripping the librariesthat libtool knows it can safely.@item --finishSame as @samp{--mode=finish}.@item --helpDisplay a help message and exit. If @samp{--mode=@var{mode}} isspecified, then detailed help for @var{mode} isdisplayed.@item --mode=@var{mode}Use @var{mode} as the operation mode. If not specified, an attempt ismade to inferr the operation mode from the @var{mode-args}. Not specifyingthe @var{mode} is currently deprecated, as there are too many situationswhere it is not possible to guess. Future versions of Libtool will requirethat @var{mode} be explicity set.@var{mode} must be set to one of the following:@table @samp@item compileCompile a source file into a libtool object.@item executeAutomatically set the library path so that another program can useuninstalled libtool-generated programs or libraries.@item finishComplete the installation of libtool libraries on the system.@item installInstall libraries or executables.@item linkCreate a library or an executable.@item uninstallDelete installed libraries or executables.@item cleanDelete uninstalled libraries or executables.@end table@item --versionPrint libtool version information and exit.@end tableThe @var{mode-args} are a variable number of arguments, depending on theselected operation mode. In general, each @var{mode-arg} is interpretedby programs libtool invokes, rather than libtool itself.@menu* Compile mode:: Creating library object files.* Link mode:: Generating executables and libraries.* Execute mode:: Debugging libtool-generated programs.* Install mode:: Making libraries and executables public.* Finish mode:: Completing a library installation.* Uninstall mode:: Removing installed executables and libraries.* Clean mode:: Removing uninstalled executables and libraries.@end menu@node Compile mode@section Compile mode@cindex mode, compile@cindex compile modeFor @dfn{compile} mode, @var{mode-args} is a compiler command to be usedin creating a `standard' object file. These arguments should begin withthe name of the C compiler, and contain the @samp{-c} compiler flag sothat only an object file is created.Libtool determines the name of the output file by removing the directorycomponent from the source file name, then substituting the source codesuffix (e.g. @samp{.c} for C source code) with the library object suffix,@samp{.lo}.If shared libraries are being built, any necessary PIC generation flagsare substituted into the compilation command. You can pass link specificflags to the compiler driver using @samp{-XCClinker @var{flag}} or passlinker flags with @samp{-Wl,@var{flag}} and @samp{-Xlinker @var{flag}}.You can also pass compile specific flags using @samp{-Wc,@var{flag}}and @samp{-Xcompiler @var{flag}}.If both PIC and non-PIC objects are being built, libtool will normallysupress the compiler output for the PIC object compilation to saveshowing very similar, if not identical duplicate output for eachobject. If the @samp{-no-suppress} option is given in compile mode,libtool will show the compiler output for both objects.If the @samp{-static} option is given, then a @samp{.o} file is built,even if libtool was configured with @samp{--disable-static}.Note that the @samp{-o} option is now fully supported. It is emulatedon the platforms that don't support it (by locking and moving theobjects), so it is really easy to use libtool, just with minormodifications to your Makefiles. Typing for example@examplelibtool gcc -c foo/x.c -o foo/x.lo@end examplewill do what you expect.Note, however, that, if the compiler does not support @samp{-c} and@samp{-o}, it is impossible to compile @file{foo/x.c} withoutoverwriting an existing @file{./x.o}. Therefore, if you do have asource file @file{./x.c}, make sure you introduce dependencies in your@file{Makefile} to make sure @file{./x.o} (or @file{./x.lo}) isre-created after any sub-directory's @file{x.lo}:@examplex.o x.lo: foo/x.lo bar/x.lo@end exampleThis will also ensure that make won't try to use a temporarily corrupted@file{x.o} to create a program or library. It may cause needlessrecompilation on platforms that support @samp{-c} and @samp{-o}together, but it's the only way to make it safe for those that don't.@node Link mode@section Link mode@cindex link mode@cindex mode, link@dfn{Link} mode links together object files (including libraryobjects) to form another library or to create an executable program.@var{mode-args} consist of a command using the C compiler to create anoutput file (with the @samp{-o} flag) from several object files.The following components of @var{mode-args} are treated specially:@table @samp@cindex undefined symbols, allowing@cindex unresolved symbols, allowing@item -all-staticIf @var{output-file} is a program, then do not link it against anyshared libraries at all. If @var{output-file} is a library, then onlycreate a static library.@item -avoid-versionTries to avoid versioning (@pxref{Versioning}) for libraries and modules,i.e. no version information is stored and no symbolic links are created.If the platform requires versioning, this option has no effect.@item -dlopen @var{file}Same as @samp{-dlpreopen @var{file}}, if native dlopening is notsupported on the host platform (@pxref{Dlopened modules}) or ifthe program is linked with @samp{-static} or @samp{-all-static}.Otherwise, no effect. If @var{file} is @code{self} libtool will makesure that the program can @code{dlopen} itself, either by enabling@code{-export-dynamic} or by falling back to @samp{-dlpreopen self}.@item -dlpreopen @var{file}Link @var{file} into the output program, and add its symbols to@var{lt_preloaded_symbols} (@pxref{Dlpreopening}). If @var{file} is@code{self}, the symbols of the program itself will be added to@var{lt_preloaded_symbols}.If @var{file} is @code{force} libtool will make sure that@var{lt_preloaded_symbols} is always @emph{defined}, regardless of whetherit's empty or not.@item -export-dynamicAllow symbols from @var{output-file} to be resolved with @code{dlsym}(@pxref{Dlopened modules}).@item -export-symbols @var{symfile}Tells the linker to export only the symbols listed in @var{symfile}.The symbol file should end in @samp{.sym} and must contain the name of onesymbol per line. This option has no effect on some platforms.By default all symbols are exported.@item -export-symbols-regex @var{regex}Same as @samp{-export-symbols}, except that only symbols matchingthe regular expression @var{regex} are exported.By default all symbols are exported.@item -L@var{libdir}Search @var{libdir} for required libraries that have already beeninstalled.@item -l@var{name}@var{output-file} requires the installed library @file{lib@var{name}}.This option is required even when @var{output-file} is not anexecutable.@item -moduleCreates a library that can be dlopened (@pxref{Dlopened modules}).This option doesn't work for programs.Module names don't need to be prefixed with 'lib'.In order to prevent name clashes, however, 'libname' and 'name'must not be used at the same time in your package.@item -no-fast-installDisable fast-install mode for the executable @var{output-file}. Usefulif the program won't be necessarily installed.@item -no-installLink an executable @var{output-file} that can't be installed andtherefore doesn't need a wrapper script. Useful if the program is onlyused in the build tree, e.g., for testing or generating other files.@item -no-undefinedDeclare that @var{output-file} does not depend on any other libraries.Some platforms cannot create shared libraries that depend on otherlibraries (@pxref{Inter-library dependencies}).@item -o @var{output-file}Create @var{output-file} from the specified objects and libraries.@item -objectlist @var{file}Use a list of object files found in @var{file} to specify objects.@item -precious-files-regex @var{regex}Prevents removal of files from the temporary output directory whosenames match this regular expression. You might specify @samp{\.bbg?$}to keep those files created with @code{gcc -ftest-coverage} for example.@item -release @var{release}Specify that the library was generated by release @var{release} of yourpackage, so that users can easily tell which versions are newer thanothers. Be warned that no two releases of your package will be binarycompatible if you use this flag. If you want binary compatibility, usethe @samp{-version-info} flag instead (@pxref{Versioning}).@item -rpath @var{libdir}If @var{output-file} is a library, it will eventually be installed in@var{libdir}. If @var{output-file} is a program, add @var{libdir} tothe run-time path of the program.@item -shrext @var{suffix}If @var{output-file} is a libtool library, replace the system's standardfile name extension for shared libraries with @var{suffix} (most systemsuse @file{.so} here). This option is helpful in certain cases where anapplication requires that shared libraries (typically modules) have anextension other than the default one. Please note you must supply thefull file name extension including any leading dot.@item -R @var{libdir}If @var{output-file} is a program, add @var{libdir} to its run-timepath. If @var{output-file} is a library, add -R@var{libdir} to its@var{dependency_libs}, so that, whenever the library is linked into aprogram, @var{libdir} will be added to its run-time path.@item -staticIf @var{output-file} is a program, then do not link it against anyuninstalled shared libtool libraries. If @var{output-file} is alibrary, then only create a static library.@item -version-info @var{current}[:@var{revision}[:@var{age}]]If @var{output-file} is a libtool library, use interface versioninformation @var{current}, @var{revision}, and @var{age} to build it(@pxref{Versioning}). Do @strong{not} use this flag to specify packagerelease information, rather see the @samp{-release} flag.@item -version-number @var{major}[:@var{minor}[:@var{revision}]]If @var{output-file} is a libtool library, compute interface versioninformation so that the resulting library uses the specified major, minor andrevision numbers. This is designed to permit libtool to be used withexisting projects where identical version numbers are already used acrossoperating systems. New projects should use the @samp{-version-info} flaginstead.@item -Wl,@var{flag}@itemx -Xlinker @var{flag}Pass a linker specific flag directly to the linker.@item -XCClinker @var{flag}Pass a link specific flag to the compiler driver (@var{CC}) during linking.@end tableIf the @var{output-file} ends in @samp{.la}, then a libtool library iscreated, which must be built only from library objects (@samp{.lo} files).The @samp{-rpath} option is required. In the current implementation,libtool libraries may not depend on other uninstalled libtool libraries(@pxref{Inter-library dependencies}).If the @var{output-file} ends in @samp{.a}, then a standard library iscreated using @code{ar} and possibly @code{ranlib}.@cindex partial linking@cindex linking, partialIf @var{output-file} ends in @samp{.o} or @samp{.lo}, then a reloadable objectfile is created from the input files (generally using @samp{ld -r}).This method is often called @dfn{partial linking}.Otherwise, an executable program is created.@node Execute mode@section Execute mode@cindex execute mode@cindex mode, executeFor @dfn{execute} mode, the library path is automatically set, then aprogram is executed.The first of the @var{mode-args} is treated as a program name, with therest as arguments to that program.The following components of @var{mode-args} are treated specially:@table @samp@item -dlopen @var{file}Add the directory containing @var{file} to the library path.@end tableThis mode sets the library path environment variable according to any@samp{-dlopen} flags.If any of the @var{args} are libtool executable wrappers, then they aretranslated into the name of their corresponding uninstalled binary, andany of their required library directories are added to the library path.@node Install mode@section Install mode@cindex install mode@cindex mode, installIn @dfn{install} mode, libtool interprets most of the elements of@var{mode-args} as an installation command beginning with@code{cp}, or a BSD-compatible @code{install} program.The following components of @var{mode-args} are treated specially:@table @samp@item -inst-prefix @var{inst-prefix-dir}When installing into a temporary staging area, rather than thefinal @var{prefix}, this argument is used to reflect thetemporary path, in much the same way @code{automake} uses@var{DESTDIR}. For instance, if @var{prefix} is @code{/usr/local},but @var{inst-prefix-dir} is @code{/tmp}, then the object will beinstalled under @code{/tmp/usr/local/}. If the installed objectis a libtool library, then the internal fields of that librarywill reflect only @var{prefix}, not @var{inst-prefix-dir}:@example# Directory that this library needs to be installed in:libdir='/usr/local/lib'@end examplenot@example# Directory that this library needs to be installed in:libdir='/tmp/usr/local/lib'@end example@code{inst-prefix} is also used to insure that if the installedobject must be relinked upon installation, that it is relinkedagainst the libraries in @var{inst-prefix-dir}/@var{prefix},not @var{prefix}.In truth, this option is not really intended for use when callinglibtool directly; it is automatically used when @code{libtool --mode=install}calls @code{libtool --mode=relink}. Libtool does this byanalyzing the destination path given in the original@code{libtool --mode=install} command and comparing it to theexpected installation path established during @code{libtool --mode=link}.Thus, end-users need change nothing, and @code{automake}-style@code{make install DESTDIR=/tmp} will Just Work(tm).@end tableThe rest of the @var{mode-args} are interpreted as arguments to the@code{cp} or @code{install} command.The command is run, and any necessary unprivileged post-installationcommands are also completed.@node Finish mode@section Finish mode@cindex finish mode@cindex mode, finish@dfn{Finish} mode helps system administrators install libtool librariesso that they can be located and linked into user programs.Each @var{mode-arg} is interpreted as the name of a library directory.Running this command may require superuser privileges, so the@samp{--dry-run} option may be useful.@node Uninstall mode@section Uninstall mode@cindex uninstall mode@cindex mode, uninstall@dfn{Uninstall} mode deletes installed libraries, executables and objects.The first @var{mode-arg} is the name of the program to use to deletefiles (typically @file{/bin/rm}).The remaining @var{mode-args} are either flags for the deletion program(beginning with a `-'), or the names of files to delete.@node Clean mode@section Clean mode@cindex clean mode@cindex mode, clean@dfn{Clean} mode deletes uninstalled libraries, executables, objectsand libtool's temporary files associated with them.The first @var{mode-arg} is the name of the program to use to deletefiles (typically @file{/bin/rm}).The remaining @var{mode-args} are either flags for the deletion program(beginning with a `-'), or the names of files to delete.@node Integrating libtool@chapter Integrating libtool with your packageThis chapter describes how to integrate libtool with your packages sothat your users can install hassle-free shared libraries.@menu* Makefile rules:: Writing @file{Makefile} rules for libtool.* Using Automake:: Automatically supporting libtool.* Configuring:: Configuring libtool for a host system.* Distributing:: What files to distribute with your package.* Static-only libraries:: Sometimes shared libraries are just a pain.@end menu@node Makefile rules@section Writing @file{Makefile} rules for libtool@cindex Makefile@cindex Makefile.am@cindex Makefile.inLibtool is fully integrated with Automake (@pxref{Top,, Introduction,automake, The Automake Manual}), starting with Automake version 1.2.If you want to use libtool in a regular @file{Makefile} (or@file{Makefile.in}), you are on your own. If you're not using Automake1.2, and you don't know how to incorporate libtool into your package youneed to do one of the following:@enumerate 1@itemDownload Automake (version 1.2 or later) from your nearest GNU mirror,install it, and start using it.@itemLearn how to write @file{Makefile} rules by hand. They're sometimes complex,but if you're clever enough to write rules for compiling your oldlibraries, then you should be able to figure out new rules for libtoollibraries (hint: examine the @file{Makefile.in} in the @file{demo}subdirectory of the libtool distribution@dots{} note especially that itwas automatically generated from the @file{Makefile.am} by Automake).@end enumerate@node Using Automake@section Using Automake with libtool@vindex LTLIBRARIESLibtool library support is implemented under the @samp{LTLIBRARIES}primary.Here are some samples from the Automake @file{Makefile.am} in thelibtool distribution's @file{demo} subdirectory.First, to link a program against a libtool library, just use the@samp{program_LDADD} variable:@examplebin_PROGRAMS = hell hell.debug# Build hell from main.c and libhello.lahell_SOURCES = main.chell_LDADD = libhello.la# Create an easier-to-debug version of hell.hell_debug_SOURCES = main.chell_debug_LDADD = libhello.lahell_debug_LDFLAGS = -static@end exampleThe flags @samp{-dlopen} or @samp{-dlpreopen} (@pxref{Link mode}) wouldfit better in the @var{program_LDADD} variable. Unfortunately, GNUautomake, up to release 1.4, doesn't accept these flags in a@var{program_LDADD} variable, so you have the following alternatives:@itemize @bullet@itemadd them to @var{program_LDFLAGS}, and list the libraries in@var{program_DEPENDENCIES}, then wait for a release of GNU automake thataccepts these flags where they belong;@itemsurround the flags between quotes, but then you must set@var{program_DEPENDENCIES} too:@exampleprogram_LDADD = "-dlopen" libfoo.laprogram_DEPENDENCIES = libfoo.la@end example@itemset and @samp{AC_SUBST} variables @var{DLOPEN} and @var{DLPREOPEN} in@file{configure.in} and use @samp{@@DLOPEN@@} and @samp{@@DLPREOPEN@@}as replacements for the explicit flags @samp{-dlopen} and@samp{-dlpreopen} in @samp{program_LDADD}. Automake will discard@samp{AC_SUBST}ed variables from dependencies, so it will behave exactlyas we expect it to behave when it accepts these flags in@samp{program_LDADD}. But hey!, this is ugly!@end itemizeYou may use the @samp{program_LDFLAGS} variable to stuff in any flagsyou want to pass to libtool while linking @samp{program} (such as@samp{-static} to avoid linking uninstalled shared libtool libraries).Building a libtool library is almost as trivial@dots{} note the use of@samp{libhello_la_LDFLAGS} to pass the @samp{-version-info}(@pxref{Versioning}) option to libtool:@example# Build a libtool library, libhello.la for installation in libdir.lib_LTLIBRARIES = libhello.lalibhello_la_SOURCES = hello.c foo.clibhello_la_LDFLAGS = -version-info 3:12:1@end exampleThe @samp{-rpath} option is passed automatically by Automake (except forlibraries listed as @code{noinst_LTLIBRARIES}), so youshould not specify it.@xref{A Shared Library, Building a Shared Library, The Automake Manual,automake, The Automake Manual}, for more information.@node Configuring@section Configuring libtool@cindex configuring libtoolLibtool requires intimate knowledge of your compiler suite and operatingsystem in order to be able to create shared libraries and link againstthem properly. When you install the libtool distribution, asystem-specific libtool script is installed into your binary directory.However, when you distribute libtool with your own packages(@pxref{Distributing}), you do not always know which compiler suite andoperating system are used to compile your package.For this reason, libtool must be @dfn{configured} before it can beused. This idea should be familiar to anybody who has used a GNU@code{configure} script. @code{configure} runs a number of tests forsystem features, then generates the @file{Makefiles} (and possibly a@file{config.h} header file), after which you can run @code{make} andbuild the package.Libtool adds its own tests to your @code{configure} script in order togenerate a libtool script for the installer's host machine.@menu* AC_PROG_LIBTOOL:: Configuring @code{libtool} in @file{configure.in}.@end menu@node AC_PROG_LIBTOOL@subsection The @code{AC_PROG_LIBTOOL} macroIf you are using GNU Autoconf (or Automake), you should add a call to@code{AC_PROG_LIBTOOL} to your @file{configure.in} file. This macroadds many new tests to the @code{configure} script so that the generatedlibtool script will understand the characteristics of the host:@defmac AC_PROG_LIBTOOL@defmacx AM_PROG_LIBTOOLAdd support for the @samp{--enable-shared} and @samp{--disable-shared}@code{configure} flags.@footnote{@code{AC_PROG_LIBTOOL} requires thatyou define the @file{Makefile} variable @code{top_builddir} in your@file{Makefile.in}. Automake does this automatically, but Autoconfusers should set it to the relative path to the top of your builddirectory (@file{../..}, for example).} @code{AM_PROG_LIBTOOL} was theold name for this macro, and although supported at the moment isdeprecated.By default, this macro turns on shared libraries if they are available,and also enables static libraries if they don't conflict with the sharedlibraries. You can modify these defaults by calling either the@code{AC_DISABLE_SHARED} or @code{AC_DISABLE_STATIC} macros:@example# Turn off shared libraries during beta-testing, since they# make the build process take too long.AC_DISABLE_SHAREDAC_PROG_LIBTOOL@end exampleThe user may specify modified forms of the configure flags@samp{--enable-shared} and @samp{--enable-static} to choose whethershared or static libraries are built based on the name of the package.For example, to have shared @samp{bfd} and @samp{gdb} libraries built,but not shared @samp{libg++}, you can run all three @code{configure}scripts as follows:@exampletrick$ ./configure --enable-shared=bfd,gdb@end exampleIn general, specifying @samp{--enable-shared=@var{pkgs}} is the same asconfiguring with @samp{--enable-shared} every package named in thecomma-separated @var{pkgs} list, and every other package with@samp{--disable-shared}. The @samp{--enable-static=@var{pkgs}} flagbehaves similarly, but it uses @samp{--enable-static} and@samp{--disable-static}. The same applies to the@samp{--enable-fast-install=@var{pkgs}} flag, which uses@samp{--enable-fast-install} and @samp{--disable-fast-install}.The package name @samp{default} matches any packages which have not settheir name in the @code{PACKAGE} environment variable.This macro also sets the shell variable @var{LIBTOOL_DEPS}, that you canuse to automatically update the libtool script if it becomesout-of-date. In order to do that, add to your @file{configure.in}:@exampleAC_PROG_LIBTOOLAC_SUBST(LIBTOOL_DEPS)@end exampleand, to @file{Makefile.in} or @file{Makefile.am}:@exampleLIBTOOL_DEPS = @@LIBTOOL_DEPS@@libtool: $(LIBTOOL_DEPS)$(SHELL) ./config.status --recheck@end exampleIf you are using GNU automake, you can omit the assignment, as automakewill take care of it. You'll obviously have to create some dependencyon @file{libtool}.@end defmac@defmac AC_LIBTOOL_DLOPENEnable checking for dlopen support. This macro should be used ifthe package makes use of the @samp{-dlopen} and @samp{-dlpreopen} flags,otherwise libtool will assume that the system does not support dlopening.The macro must be called @strong{before} @code{AC_PROG_LIBTOOL}.@end defmac@defmac AC_LIBTOOL_WIN32_DLLThis macro should be used if the package has been ported to build cleandlls on win32 platforms. Usually this means that any library data itemsare exported with @code{__declspec(dllexport)} and imported with@code{__declspec(dllimport)}. If this macro is not used, libtool willassume that the package libraries are not dll clean and will build onlystatic libraries on win32 hosts.This macro must be called @strong{before} @code{AC_PROG_LIBTOOL}, andprovision must be made to pass @samp{-no-undefined} to @code{libtool}in link mode from the package @code{Makefile}. Naturally, if you pass@samp{-no-undefined}, you must ensure that all the library symbols@strong{really are} defined at link time!@end defmac@defmac AC_DISABLE_FAST_INSTALLChange the default behaviour for @code{AC_PROG_LIBTOOL} to disableoptimization for fast installation. The user may still override thisdefault, depending on platform support, by specifying@samp{--enable-fast-install}.@end defmac@defmac AC_DISABLE_SHARED@defmacx AM_DISABLE_SHAREDChange the default behaviour for @code{AC_PROG_LIBTOOL} to disableshared libraries. The user may still override this default byspecifying @samp{--enable-shared}.@end defmac@defmac AC_DISABLE_STATIC@defmacx AM_DISABLE_STATICChange the default behaviour for @code{AC_PROG_LIBTOOL} to disablestatic libraries. The user may still override this default byspecifying @samp{--enable-static}.@end defmacThe tests in @code{AC_PROG_LIBTOOL} also recognize the followingenvironment variables:@defvar CCThe C compiler that will be used by the generated @code{libtool}. Ifthis is not set, @code{AC_PROG_LIBTOOL} will look for @code{gcc} or@code{cc}.@end defvar@defvar CFLAGSCompiler flags used to generate standard object files. If this is notset, @code{AC_PROG_LIBTOOL} will not use any such flags. It affectsonly the way @code{AC_PROG_LIBTOOL} runs tests, not the produced@code{libtool}.@end defvar@defvar CPPFLAGSC preprocessor flags. If this is not set, @code{AC_PROG_LIBTOOL} willnot use any such flags. It affects only the way @code{AC_PROG_LIBTOOL}runs tests, not the produced @code{libtool}.@end defvar@defvar LDThe system linker to use (if the generated @code{libtool} requires one).If this is not set, @code{AC_PROG_LIBTOOL} will try to find out what isthe linker used by @var{CC}.@end defvar@defvar LDFLAGSThe flags to be used by @code{libtool} when it links a program. Ifthis is not set, @code{AC_PROG_LIBTOOL} will not use any such flags. Itaffects only the way @code{AC_PROG_LIBTOOL} runs tests, not the produced@code{libtool}.@end defvar@defvar LIBSThe libraries to be used by @code{AC_PROG_LIBTOOL} when it links aprogram. If this is not set, @code{AC_PROG_LIBTOOL} will not use anysuch flags. It affects only the way @code{AC_PROG_LIBTOOL} runs tests,not the produced @code{libtool}.@end defvar@defvar NMProgram to use rather than checking for @code{nm}.@end defvar@defvar RANLIBProgram to use rather than checking for @code{ranlib}.@end defvar@defvar LN_SA command that creates a link of a program, a soft-link if possible, ahard-link otherwise. @code{AC_PROG_LIBTOOL} will check for a suitableprogram if this variable is not set.@end defvar@defvar DLLTOOLProgram to use rather than checking for @code{dlltool}. Only meaningfulfor Cygwin/MS-Windows.@end defvar@defvar OBJDUMPProgram to use rather than checking for @code{objdump}. Only meaningfulfor Cygwin/MS-Windows.@end defvar@defvar ASProgram to use rather than checking for @code{as}. Only used onCygwin/MS-Windows at the moment.@end defvar@pindex aclocalWhen you invoke the @code{libtoolize} program (@pxref{Invokinglibtoolize}), it will tell you where to find a definition of@code{AC_PROG_LIBTOOL}. If you use Automake, the @code{aclocal} programwill automatically add @code{AC_PROG_LIBTOOL} support to your@code{configure} script.Nevertheless, it is advisable to include a copy of @file{libtool.m4} in@file{acinclude.m4}, so that, even if @file{aclocal.m4} and@file{configure} are rebuilt for any reason, the appropriate libtoolmacros will be used. The alternative is to hope the user will have acompatible version of @file{libtool.m4} installed and accessible for@code{aclocal}. This may lead to weird errors when versions don'tmatch.@node Distributing@section Including libtool in your packageIn order to use libtool, you need to include the following files withyour package:@table @file@item config.guess@pindex config.guessAttempt to guess a canonical system name.@item config.sub@pindex config.subCanonical system name validation subroutine script.@item install-sh@pindex install-shBSD-compatible @command{install} replacement script.@item ltmain.sh@pindex ltmain.shA generic script implementing basic libtool functionality.@end tableNote that the libtool script itself should @emph{not} be included withyour package. @xref{Configuring}.You should use the @code{libtoolize} program, rather than manuallycopying these files into your package. Note however, that @file{install-sh}is not copied by @code{libtoolize}; if you use Automake, it will take careof that, otherwise you may obtain a copy from the package data directoryof the installed Libtool. This may change in a future Libtool version.@menu* Invoking libtoolize:: @code{libtoolize} command line options.* Autoconf .o macros:: Autoconf macros that set object file names.@end menu@node Invoking libtoolize@subsection Invoking @code{libtoolize}@pindex libtoolize@cindex libtoolize command options@cindex command options, libtoolize@cindex options, libtoolize commandThe @code{libtoolize} program provides a standard way to add libtoolsupport to your package. In the future, it may implement better usagechecking, or other features to make libtool even easier to use.The @code{libtoolize} program has the following synopsis:@examplelibtoolize [@var{option}]@dots{}@end example@noindentand accepts the following options:@table @samp@item --automakeWork silently, and assume that Automake libtool support is used.@samp{libtoolize --automake} is used by Automake to add libtool files toyour package, when @code{AC_PROG_LIBTOOL} appears in your@file{configure.in}.@item --copy@itemx -cCopy files from the libtool data directory rather than creatingsymlinks.@item --debugDump a trace of shell script execution to standard output. Thisproduces a lot of output, so you may wish to pipe it to @code{less} (or@code{more}) or redirect to a file.@item --dry-run@itemx -nDon't run any commands that modify the file system, just print themout.@item --force@itemx -fReplace existing libtool files. By default, @code{libtoolize} won'toverwrite existing files.@item --helpDisplay a help message and exit.@item --ltdlInstall libltdl in a subdirectory of your package.@item --ltdl-tarAdd the file libltdl.tar.gz to your package.@item --versionPrint @code{libtoolize} version information and exit.@end table@findex AC_CONFIG_AUX_DIRIf @code{libtoolize} detects an explicit call to@code{AC_CONFIG_AUX_DIR} (@pxref{Input, , The Autoconf Manual,autoconf, The Autoconf Manual}) in your @file{configure.in}, itwill put the files in the specified directory.@code{libtoolize} displays hints for adding libtool support to yourpackage, as well.@node Autoconf .o macros@subsection Autoconf @samp{.o} macrosThe Autoconf package comes with a few macros that run tests, then set avariable corresponding to the name of an object file. Sometimes it isnecessary to use corresponding names for libtool objects.Here are the names of variables that list libtool objects:@defvar LTALLOCA@findex AC_FUNC_ALLOCASubstituted by @code{AC_FUNC_ALLOCA} (@pxref{Particular Functions, ParticularFunction Checks, The Autoconf Manual, autoconf, The AutoconfManual}). Is either empty, or contains @samp{alloca.lo}.@end defvar@defvar LTLIBOBJS@findex AC_REPLACE_FUNCSSubstituted by @code{AC_REPLACE_FUNCS} (@pxref{Generic Functions, GenericFunction Checks, The Autoconf Manual, autoconf, The AutoconfManual}), and a few other functions.@end defvarUnfortunately, the stable release of Autoconf (2.13, at the time ofthis writing) does not have any way for libtool to provide support forthese variables. So, if you depend on them, use the following codeimmediately before the call to @code{AC_OUTPUT} in your@file{configure.in}:@exampleLTLIBOBJS=`echo "$LIBOBJS" | sed 's/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'`AC_SUBST(LTLIBOBJS)LTALLOCA=`echo "$ALLOCA" | sed 's/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'`AC_SUBST(LTALLOCA)AC_OUTPUT(@dots{})@end example@node Static-only libraries@section Static-only libraries@cindex debugging libraries@cindex developing libraries@cindex double-compilation, avoiding@cindex avoiding shared libraries@cindex eliding shared libraries@cindex using shared libraries, not@cindex shared libraries, not using@cindex time, saving@cindex saving timeWhen you are developing a package, it is often worthwhile to configureyour package with the @samp{--disable-shared} flag, or to override thedefaults for @code{AC_PROG_LIBTOOL} by using the@code{AC_DISABLE_SHARED} Autoconf macro (@pxref{AC_PROG_LIBTOOL, , The@code{AC_PROG_LIBTOOL} macro}). This prevents libtool from buildingshared libraries, which has several advantages:@itemize @bullet@itemcompilation is twice as fast, which can speed up your development cycle,@itemdebugging is easier because you don't need to deal with any complexitiesadded by shared libraries, and@itemyou can see how libtool behaves on static-only platforms.@end itemizeYou may want to put a small note in your package @file{README} to letother developers know that @samp{--disable-shared} can save them time.The following example note is taken from the GIMP@footnote{GNU ImageManipulation Program, for those who haven't taken the plunge. See@url{http://www.gimp.org/}.} distribution @file{README}:@exampleThe GIMP uses GNU Libtool in order to build shared libraries on avariety of systems. While this is very nice for making usablebinaries, it can be a pain when trying to debug a program. For thatreason, compilation of shared libraries can be turned off byspecifying the @samp{--disable-shared} option to @file{configure}.@end example@node Versioning@chapter Library interface versions@cindex dynamic dependencies@cindex dependency versioning@cindex shared library versionsThe most difficult issue introduced by shared libraries is that ofcreating and resolving runtime dependencies. Dependencies on programsand libraries are often described in terms of a single name, such as@code{sed}. So, one may say ``libtool depends on sed,'' and that isgood enough for most purposes.However, when an interface changes regularly, we need to be morespecific: ``Gnus 5.1 requires Emacs 19.28 or above.'' Here, thedescription of an interface consists of a name, and a ``versionnumber.''Even that sort of description is not accurate enough for some purposes.What if Emacs 20 changes enough to break Gnus 5.1?The same problem exists in shared libraries: we require a formal versionsystem to describe the sorts of dependencies that programs have onshared libraries, so that the dynamic linker can guarantee that programsare linked only against libraries that provide the interface theyrequire.@menu* Interfaces:: What are library interfaces?* Libtool versioning:: Libtool's versioning system.* Updating version info:: Changing version information before releases.* Release numbers:: Breaking binary compatibility for aesthetics.@end menu@node Interfaces@section What are library interfaces?@cindex library interfacesInterfaces for libraries may be any of the following (and more):@itemize @bullet@itemglobal variables: both names and types@itemglobal functions: argument types and number, return types, and function names@itemstandard input, standard output, standard error, and file formats@itemsockets, pipes, and other inter-process communication protocol formats@end itemizeNote that static functions do not count as interfaces, because they arenot directly available to the user of the library.@node Libtool versioning@section Libtool's versioning system@cindex libtool library versions@cindex formal versioning@cindex versioning, formalLibtool has its own formal versioning system. It is not as flexible assome, but it is definitely the simplest of the more powerful versioningsystems.Think of a library as exporting several sets of interfaces, arbitrarilyrepresented by integers. When a program is linked against a library, itmay use any subset of those interfaces.Libtool's description of the interfaces that a program uses is simple:it encodes the least and the greatest interface numbers in the resultingbinary (@var{first-interface}, @var{last-interface}).The dynamic linker is guaranteed that if a library supports @emph{every}interface number between @var{first-interface} and @var{last-interface},then the program can be relinked against that library.Note that this can cause problems because libtool's compatibilityrequirements are actually stricter than is necessary.Say @file{libhello} supports interfaces 5, 16, 17, 18, and 19, and thatlibtool is used to link @file{test} against @file{libhello}.Libtool encodes the numbers 5 and 19 in @file{test}, and the dynamiclinker will only link @file{test} against libraries that support@emph{every} interface between 5 and 19. So, the dynamic linker refusesto link @file{test} against @file{libhello}!In order to eliminate this problem, libtool only allows libraries todeclare consecutive interface numbers. So, @file{libhello} can declare atmost that it supports interfaces 16 through 19. Then, the dynamiclinker will link @file{test} against @file{libhello}.So, libtool library versions are described by three integers:@table @var@item currentThe most recent interface number that this library implements.@item revisionThe implementation number of the @var{current} interface.@item ageThe difference between the newest and oldest interfaces that thislibrary implements. In other words, the library implements all theinterface numbers in the range from number @code{@var{current} -@var{age}} to @code{@var{current}}.@end tableIf two libraries have identical @var{current} and @var{age} numbers,then the dynamic linker chooses the library with the greater@var{revision} number.@node Updating version info@section Updating library version informationIf you want to use libtool's versioning system, then you must specifythe version information to libtool using the @samp{-version-info} flagduring link mode (@pxref{Link mode}).This flag accepts an argument of the form@samp{@var{current}[:@var{revision}[:@var{age}]]}. So, passing@samp{-version-info 3:12:1} sets @var{current} to 3, @var{revision} to12, and @var{age} to 1.If either @var{revision} or @var{age} are omitted, they default to 0.Also note that @var{age} must be less than or equal to the @var{current}interface number.Here are a set of rules to help you update your library versioninformation:@enumerate 1@itemStart with version information of @samp{0:0:0} for each libtool library.@itemUpdate the version information only immediately before a public releaseof your software. More frequent updates are unnecessary, and onlyguarantee that the current interface number gets larger faster.@itemIf the library source code has changed at all since the last update,then increment @var{revision} (@samp{@var{c}:@var{r}:@var{a}} becomes@samp{@var{c}:@math{r+1}:@var{a}}).@itemIf any interfaces have been added, removed, or changed since the lastupdate, increment @var{current}, and set @var{revision} to 0.@itemIf any interfaces have been added since the last public release, thenincrement @var{age}.@itemIf any interfaces have been removed since the last public release, thenset @var{age} to 0.@end enumerate@strong{@emph{Never}} try to set the interface numbers so that theycorrespond to the release number of your package. This is an abuse thatonly fosters misunderstanding of the purpose of library versions.Instead, use the @samp{-release} flag (@pxref{Release numbers}), but bewarned that every release of your package will not be binary compatiblewith any other release.@node Release numbers@section Managing release informationOften, people want to encode the name of the package release into theshared library so that it is obvious to the user which package theirprograms are linked against. This convention is used especially onGNU/Linux:@exampletrick$ @kbd{ls /usr/lib/libbfd*}/usr/lib/libbfd.a /usr/lib/libbfd.so.2.7.0.2/usr/lib/libbfd.sotrick$@end exampleOn @samp{trick}, @file{/usr/lib/libbfd.so} is a symbolic link to@file{libbfd.so.2.7.0.2}, which was distributed as a part of@samp{binutils-2.7.0.2}.Unfortunately, this convention conflicts directly with libtool's idea oflibrary interface versions, because the library interface rarely changesat the same time that the release number does, and the library suffix isnever the same across all platforms.So, in order to accommodate both views, you can use the @samp{-release}flag in order to set release information for libraries which you do notwant to use @samp{-version-info}. For the @file{libbfd} example, thenext release which uses libtool should be built with @samp{-release2.9.0}, which will produce the following files on GNU/Linux:@exampletrick$ @kbd{ls /usr/lib/libbfd*}/usr/lib/libbfd-2.9.0.so /usr/lib/libbfd.a/usr/lib/libbfd.sotrick$@end exampleIn this case, @file{/usr/lib/libbfd.so} is a symbolic link to@file{libbfd-2.9.0.so}. This makes it obvious that the user is dealingwith @samp{binutils-2.9.0}, without compromising libtool's idea ofinterface versions.Note that this option causes a modification of the library name, so donot use it unless you want to break binary compatibility with any pastlibrary releases. In general, you should only use @samp{-release} forpackage-internal libraries or for ones whose interfaces change veryfrequently.@node Library tips@chapter Tips for interface design@cindex library interfaces, design@cindex design of library interfacesWriting a good library interface takes a lot of practice and thoroughunderstanding of the problem that the library is intended to solve.If you design a good interface, it won't have to change often, you won'thave to keep updating documentation, and users won't have to keeprelearning how to use the library.Here is a brief list of tips for library interface design, which mayhelp you in your exploits:@table @asis@item Plan aheadTry to make every interface truly minimal, so that you won't need todelete entry points very often.@item Avoid interface changes@cindex renaming interface functionsSome people love redesigning and changing entry points just for the heckof it (note: @emph{renaming} a function is considered changing an entrypoint). Don't be one of those people. If you must redesign aninterface, then try to leave compatibility functions behind so thatusers don't need to rewrite their existing code.@item Use opaque data types@cindex opaque data typesThe fewer data type definitions a library user has access to, thebetter. If possible, design your functions to accept a generic pointer(which you can cast to an internal data type), and provide accessfunctions rather than allowing the library user to directly manipulatethe data.That way, you have the freedom to change the data structures withoutchanging the interface.This is essentially the same thing as using abstract data types andinheritance in an object-oriented system.@item Use header files@cindex header filesIf you are careful to document each of your library's global functionsand variables in header files, and include them in your library sourcefiles, then the compiler will let you know if you make any interfacechanges by accident (@pxref{C header files}).@item Use the @code{static} keyword (or equivalent) whenever possible@cindex global functionsThe fewer global functions your library has, the more flexibility you'llhave in changing them. Static functions and variables may change formsas often as you like@dots{} your users cannot access them, so theyaren't interface changes.@item Be careful with array dimensionsThe number of elements in a global array is part of an interface, evenif the header just declares @code{extern int foo[];}. This is becauseon i386 and some other SVR4/ELF systems, when an applicationreferences data in a shared library the size of that data (whateverits type) is included in the application executable. If you mightwant to change the size of an array or string then provide a pointernot the actual array.@end table@menu* C header files:: How to write portable include files.@end menu@node C header files@section Writing C header files@cindex portable C headers@cindex C header files, portable@cindex include files, portableWriting portable C header files can be difficult, since they may be readby different types of compilers:@table @asis@item C++ compilersC++ compilers require that functions be declared with full prototypes,since C++ is more strongly typed than C. C functions and variables alsoneed to be declared with the @code{extern "C"} directive, so that thenames aren't mangled. @xref{C++ libraries}, for other issues relevantto using C++ with libtool.@item ANSI C compilersANSI C compilers are not as strict as C++ compilers, but functionsshould be prototyped to avoid unnecessary warnings when the header fileis @code{#include}d.@item non-ANSI C compilersNon-ANSI compilers will report errors if functions are prototyped.@end tableThese complications mean that your library interface headers must usesome C preprocessor magic in order to be usable by each of the abovecompilers.@file{foo.h} in the @file{demo} subdirectory of the libtool distributionserves as an example for how to write a header file that can besafely installed in a system directory.Here are the relevant portions of that file:@example/* BEGIN_C_DECLS should be used at the beginning of your declarations,so that C++ compilers don't mangle their names. Use END_C_DECLS atthe end of C declarations. */#undef BEGIN_C_DECLS#undef END_C_DECLS#ifdef __cplusplus# define BEGIN_C_DECLS extern "C" @{# define END_C_DECLS @}#else# define BEGIN_C_DECLS /* empty */# define END_C_DECLS /* empty */#endif/* PARAMS is a macro used to wrap function prototypes, so thatcompilers that don't understand ANSI C prototypes still work,and ANSI C compilers can issue warnings about type mismatches. */#undef PARAMS#if defined (__STDC__) || defined (_AIX) \|| (defined (__mips) && defined (_SYSTYPE_SVR4)) \|| defined(WIN32) || defined(__cplusplus)# define PARAMS(protos) protos#else# define PARAMS(protos) ()#endif@end exampleThese macros are used in @file{foo.h} as follows:@example#ifndef FOO_H#define FOO_H 1/* The above macro definitions. */#include "@dots{}"BEGIN_C_DECLSint foo PARAMS((void));int hello PARAMS((void));END_C_DECLS#endif /* !FOO_H */@end exampleNote that the @file{#ifndef FOO_H} prevents the body of @file{foo.h}from being read more than once in a given compilation.Also the only thing that must go outside the@code{BEGIN_C_DECLS}/@code{END_C_DECLS} pair are @code{#include} lines.Strictly speaking it is only C symbol names that need to be protected,but your header files will be more maintainable if you have a singlepair of of these macros around the majority of the header contents.You should use these definitions of @code{PARAMS}, @code{BEGIN_C_DECLS},and @code{END_C_DECLS} into your own headers. Then, you may use them tocreate header files that are valid for C++, ANSI, and non-ANSIcompilers@footnote{We used to recommend @code{__P},@code{__BEGIN_DECLS} and @code{__END_DECLS}. This was bad advice sincesymbols (even preprocessor macro names) that begin with an underscoreare reserved for the use of the compiler.}.Do not be naive about writing portable code. Following the tips givenabove will help you miss the most obvious problems, but there aredefinitely other subtle portability issues. You may need to cope withsome of the following issues:@itemize @bullet@itemPre-ANSI compilers do not always support the @code{void *} genericpointer type, and so need to use @code{char *} in its place.@itemThe @code{const}, @code{inline} and @code{signed} keywords are notsupported by some compilers, especially pre-ANSI compilers.@itemThe @code{long double} type is not supported by many compilers.@end itemize@node Inter-library dependencies@chapter Inter-library dependencies@cindex dependencies between libraries@cindex inter-library dependenciesBy definition, every shared library system provides a way forexecutables to depend on libraries, so that symbol resolution isdeferred until runtime.An @dfn{inter-library dependency} is one in which a library depends onother libraries. For example, if the libtool library @file{libhello}uses the @code{cos} function, then it has an inter-library dependencyon @file{libm}, the math library that implements @code{cos}.Some shared library systems provide this feature in aninternally-consistent way: these systems allow chains of dependencies ofpotentially infinite length.However, most shared library systems are restricted in that they onlyallow a single level of dependencies. In these systems, programs maydepend on shared libraries, but shared libraries may not depend on othershared libraries.In any event, libtool provides a simple mechanism for you to declareinter-library dependencies: for every library @file{lib@var{name}} thatyour own library depends on, simply add a corresponding@code{-l@var{name}} option to the link line when you create yourlibrary. To make an example of our@file{libhello} that depends on @file{libm}:@exampleburger$ @kbd{libtool --mode=link gcc -g -O -o libhello.la foo.lo hello.lo \-rpath /usr/local/lib -lm}burger$@end exampleWhen you link a program against @file{libhello}, you don't need tospecify the same @samp{-l} options again: libtool will do that for you,in order to guarantee that all the required libraries are found. Thisrestriction is only necessary to preserve compatibility with staticlibrary systems and simple dynamic library systems.Some platforms, such as AIX, do not even allow you thisflexibility. In order to build a shared library, it must be entirelyself-contained (that is, have references only to symbols that are foundin the @samp{.lo} files or the specified @samp{-l} libraries), and youneed to specify the @var{-no-undefined} flag. By default, libtoolbuilds only static libraries on these kinds of platforms.The simple-minded inter-library dependency tracking code of libtoolreleases prior to 1.2 was disabled because it was not clear when it waspossible to link one library with another, and complex failures wouldoccur. A more complex implementation of this concept was re-introducedbefore release 1.3, but it has not been ported to all platforms thatlibtool supports. The default, conservative behavior is to avoidlinking one library with another, introducing their inter-dependenciesonly when a program is linked with them.@node Dlopened modules@chapter Dlopened modules@findex dlopen@findex dlsym@findex dlclose@findex shl_load@cindex dynamic linking, applications@cindex dlopening modules@cindex modules, dynamic@cindex application-level dynamic linkingIt can sometimes be confusing to discuss @dfn{dynamic linking}, becausethe term is used to refer to two different concepts:@enumerate 1@itemCompiling and linking a program against a shared library, which isresolved automatically at run time by the dynamic linker. In thisprocess, dynamic linking is transparent to the application.@itemThe application calling functions such as @code{dlopen},@footnote{HP-UX,to be different, uses a function named @code{shl_load}.} which loadarbitrary, user-specified modules at runtime. This type of dynamiclinking is explicitly controlled by the application.@end enumerateTo mitigate confusion, this manual refers to the second type of dynamiclinking as @dfn{dlopening} a module.The main benefit to dlopening object modules is the ability to accesscompiled object code to extend your program, rather than using aninterpreted language. In fact, dlopen calls are frequently used inlanguage interpreters to provide an efficient way to extend thelanguage.As of version @value{VERSION}, libtool provides support for dlopenedmodules. However, you should indicate that your package is willing touse such support, by using the macro @samp{AC_LIBTOOL_DLOPEN} in@file{configure.in}. If this macro is not used (or it is used@emph{after} @samp{AC_PROG_LIBTOOL}), libtool will assume no dlopeningmechanism is available, and will try to simulate it.This chapter discusses how you as a dlopen application developer mightuse libtool to generate dlopen-accessible modules.@menu* Building modules:: Creating dlopenable objects and libraries.* Dlpreopening:: Dlopening that works on static platforms.* Finding the dlname:: Choosing the right file to @code{dlopen}.* Dlopen issues:: Unresolved problems that need your attention.@end menu@node Building modules@section Building modules to dlopenOn some operating systems, a program symbol must be specially declaredin order to be dynamically resolved with the @code{dlsym} (orequivalent) function.Libtool provides the @samp{-export-dynamic} and @samp{-module}link flags (@pxref{Link mode}), which do this declaration.You need to use these flags if you are linking an application program thatdlopens other modules or a libtool library that will also be dlopened.For example, if we wanted to build a shared library, @file{libhello},that would later be dlopened by an application, we would add@samp{-module} to the other link flags:@exampleburger$ @kbd{libtool --mode=link gcc -module -o libhello.la foo.lo \hello.lo -rpath /usr/local/lib -lm}burger$@end exampleIf symbols from your @emph{executable} are needed to satisfy unresolvedreferences in a library you want to dlopen you will have to use the flag@samp{-export-dynamic}.You should use @samp{-export-dynamic} while linking the executable that callsdlopen:@exampleburger$ @kbd{libtool --mode=link gcc -export-dynamic -o hell-dlopener main.o}burger$@end example@node Dlpreopening@section DlpreopeningLibtool provides special support for dlopening libtool object andlibtool library files, so that their symbols can be resolved @emph{evenon platforms without any @code{dlopen} and @code{dlsym}functions}.Consider the following alternative ways of loading code into yourprogram, in order of increasing ``laziness'':@enumerate 1@itemLinking against object files that become part of the program executable,whether or not they are referenced. If an object file cannot be found,then the linker refuses to create the executable.@itemDeclaring a static library to the linker, so that it is searched at linktime in order to satisfy any undefined references in the above objectfiles. If the static library cannot be found, then the linker refusesto link the executable.@itemDeclaring a shared library to the runtime linker, so that it is searchedat runtime in order to satisfy any undefined references in the abovefiles. If the shared library cannot be found, then the dynamic linkeraborts the program before it runs.@itemDlopening a module, so that the application can resolve its own,dynamically-computed references. If there is an error opening themodule, or the module is not found, then the application can recoverwithout crashing.@end enumerateLibtool emulates @samp{-dlopen} on static platforms by linking objectsinto the program at compile time, and creating data structures thatrepresent the program's symbol table.In order to use this feature, you must declare the objects you want yourapplication to dlopen by using the @samp{-dlopen} or @samp{-dlpreopen}flags when you link your program (@pxref{Link mode}).@deftypefn {Structure} {struct} lt_dlsymlist @{ @w{const char *@var{name};} @w{lt_ptr @var{address};} @}The @var{name} attribute is a null-terminated character string of thesymbol name, such as @code{"fprintf"}. The @var{address} attribute is ageneric pointer to the appropriate object, such as @code{&fprintf}.@end deftypefn@deftypevar {const lt_dlsymlist *} lt_preloaded_symbolsAn array of @var{lt_symbol} structures, representing all the preloadedsymbols linked into the program. For each @samp{-dlpreloaded} filethere is an element with the @var{name} of the file and a @var{address}of @code{0}, followed by all symbols exported from this file.For the executable itself the special name @@PROGRAM@@ is used.The last element has a @var{name} and @var{address} of @code{0}.@end deftypevarSome compilers may allow identifiers which are not valid in ANSI C, suchas dollar signs. Libtool only recognizes valid ANSI C symbols (aninitial ASCII letter or underscore, followed by zero or more ASCIIletters, digits, and underscores), so non-ANSI symbols will not appearin @var{lt_preloaded_symbols}.@node Finding the dlname@section Finding the correct name to dlopen@cindex names of dynamic modules@cindex dynamic modules, namesAfter a library has been linked with @samp{-module}, it can be dlopened.Unfortunately, because of the variation in library names,your package needs to determine the correct file to dlopen.The most straightforward and flexible implementation is to determine thename at runtime, by finding the installed @samp{.la} file, and searchingit for the following lines:@example# The name that we can @code{dlopen}.dlname='@var{dlname}'@end exampleIf @var{dlname} is empty, then the library cannot be dlopened.Otherwise, it gives the dlname of the library. So, if the library wasinstalled as @file{/usr/local/lib/libhello.la}, and the @var{dlname} was@file{libhello.so.3}, then @file{/usr/local/lib/libhello.so.3} should bedlopened.If your program uses this approach, then it should search thedirectories listed in the @code{LD_LIBRARY_PATH}@footnote{@code{LIBPATH}on AIX, and @code{SHLIB_PATH} on HP-UX.} environment variable, as well asthe directory where libraries will eventually be installed. Searchingthis variable (or equivalent) will guarantee that your program can findits dlopened modules, even before installation, provided you have linkedthem using libtool.@node Dlopen issues@section Unresolved dlopen issues@cindex pitfalls with dlopen@cindex dlopening, pitfalls@cindex trouble with dlopenThe following problems are not solved by using libtool's dlopen support:@itemize @bullet@itemDlopen functions are generally only available on shared libraryplatforms. If you want your package to be portable to static platforms,you have to use either libltdl (@pxref{Using libltdl}) or develop yourown alternatives to dlopening dynamic code.Most reasonable solutions involve writing wrapper functions for the@code{dlopen} family, which do package-specific tricks when dlopeningis unsupported or not available on a given platform.@itemThere are major differences in implementations of the @code{dlopen}family of functions. Some platforms do not even use the same functionnames (notably HP-UX, with its @code{shl_load} family).@itemThe application developer must write a custom search function in orderto discover the correct module filename to supply to @code{dlopen}.@end itemize@node Using libltdl@chapter Using libltdl@findex libltdl@findex dlopen@findex dlsym@findex dlclose@findex dlerror@findex shl_load@cindex dynamic linking, applications@cindex dlopening modules@cindex modules, dynamic@cindex application-level dynamic linkingLibtool provides a small library, called @file{libltdl}, that aims athiding the various difficulties of dlopening libraries from programmers.It consists of a header-file and a small C source file that can bedistributed with applications that need dlopening functionality. Onsome platforms, whose dynamic linkers are too limited for a simpleimplementation of @file{libltdl} services, it requires GNU DLD, or itwill only emulate dynamic linking with libtool's dlpreopening mechanism.@noindentlibltdl supports currently the following dynamic linking mechanisms:@itemize @bullet@item@code{dlopen} (Solaris, Linux and various BSD flavors)@item@code{shl_load} (HP-UX)@item@code{LoadLibrary} (Win16 and Win32)@item@code{load_add_on} (BeOS)@itemGNU DLD (emulates dynamic linking for static libraries)@itemlibtool's dlpreopen (see @pxref{Dlpreopening})@end itemize@noindentlibltdl is licensed under the terms of the GNU Library General Public License,with the following exception:@quotationAs a special exception to the GNU Lesser General Public License,if you distribute this file as part of a program or library thatis built using GNU libtool, you may include it under the samedistribution terms that you use for the rest of that program.@end quotation@menu* Libltdl interface:: How to use libltdl in your programs.* Modules for libltdl:: Creating modules that can be @code{dlopen}ed.* Thread Safety in libltdl:: Registering callbacks for multi-thread safety.* User defined module data:: Associating data with loaded modules.* Module loaders for libltdl:: Creating user defined module loaders.* Distributing libltdl:: How to distribute libltdl with your package.@end menu@node Libltdl interface@section How to use libltdl in your programs@noindentThe libltdl API is similar to the dlopen interface of Solaris and Linux,which is very simple but powerful.@noindentTo use libltdl in your program you have to include the header file @file{ltdl.h}:@example#include <ltdl.h>@end example@noindentThe last release of libltdl used some symbols that violated the@sc{posix} namespace conventions. These symbols are now deprecated,and have been replaced by those described here. If you have code thatrelies on the old deprecated symbol names, defining@samp{LT_NON_POSIX_NAMESPACE} before you include @file{ltdl.h} providesconversion macros. Whichever set of symbols you use, the new api isnot binary compatible with the last, so you will need to recompileyour application in order to use this version of libltdl.@noindentNote that libltdl is not threadsafe, i.e. a multithreaded applicationhas to use a mutex for libltdl. It was reported that GNU/Linux's glibc2.0's @code{dlopen} with @samp{RTLD_LAZY} (which libltdl uses bydefault) is not thread-safe, but this problem is supposed to be fixed inglibc 2.1. On the other hand, @samp{RTLD_NOW} was reported to introduceproblems in multi-threaded applications on FreeBSD. Working aroundthese problems is left as an exercise for the reader; contributions arecertainly welcome.@noindentThe following types are defined in @file{ltdl.h}:@deftp {Type} lt_ptr@code{lt_ptr} is a generic pointer.@end deftp@deftp {Type} lt_dlhandle@code{lt_dlhandle} is a module "handle".Every lt_dlopened module has a handle associated with it.@end deftp@deftp {Type} lt_dlsymlist@code{lt_dlsymlist} is a symbol list for dlpreopened modules.This structure is described in @pxref{Dlpreopening}.@end deftp@page@noindentlibltdl provides the following functions:@deftypefun int lt_dlinit (void)Initialize libltdl.This function must be called before using libltdland may be called several times.Return 0 on success, otherwise the number of errors.@end deftypefun@deftypefun int lt_dlexit (void)Shut down libltdl and close all modules.This function will only then shut down libltdl when it was called asmany times as @code{lt_dlinit} has been successfully called.Return 0 on success, otherwise the number of errors.@end deftypefun@deftypefun lt_dlhandle lt_dlopen (const char *@var{filename})Open the module with the file name @var{filename} and return ahandle for it. @code{lt_dlopen} is able to open libtool dynamicmodules, preloaded static modules, the program itself andnative dynamic libraries.Unresolved symbols in the module are resolved using its dependencylibraries (not implemented yet) and previously dlopened modules. If theexecutable using this module was linked with the @code{-export-dynamic}flag, then the global symbols in the executable will also be used toresolve references in the module.If @var{filename} is @code{NULL} and the program was linked with@code{-export-dynamic} or @code{-dlopen self}, @code{lt_dlopen} willreturn a handle for the program itself, which can be used to access itssymbols.If libltdl cannot find the library and the file name @var{filename} doesnot have a directory component it will additionally search in thefollowing search paths for the module (in the order as follows):@enumerate 1@item user-defined search path:This search path can be changed by the program using thefunctions @code{lt_dlsetsearchpath}, @code{lt_dladdsearchdir} and@code{lt_dlinsertsearchdir}.@item libltdl's search path:This search path is the value of the environment variable@var{LTDL_LIBRARY_PATH}.@item system library search path:The system dependent library search path(e.g. on Linux it is @var{LD_LIBRARY_PATH}).@end enumerateEach search path must be a colon-separated list of absolute directories,for example, @code{"/usr/lib/mypkg:/lib/foo"}.If the same module is loaded several times, the same handle is returned.If @code{lt_dlopen} fails for any reason, it returns @code{NULL}.@end deftypefun@deftypefun lt_dlhandle lt_dlopenext (const char *@var{filename})The same as @code{lt_dlopen}, except that it tries to appenddifferent file name extensions to the file name.If the file with the file name @var{filename} cannot be foundlibltdl tries to append the following extensions:@enumerate 1@item the libtool archive extension @samp{.la}@item the extension used for native dynamic libraries on the host platform,e.g., @samp{.so}, @samp{.sl}, etc.@end enumerateThis lookup strategy was designed to allow programs that don'thave knowledge about native dynamic libraries naming conventionsto be able to @code{dlopen} such libraries as well as libtool modulestransparently.@end deftypefun@deftypefun int lt_dlclose (lt_dlhandle @var{handle})Decrement the reference count on the module @var{handle}.If it drops to zero and no other module depends on this module,then the module is unloaded.Return 0 on success.@end deftypefun@deftypefun lt_ptr lt_dlsym (lt_dlhandle @var{handle}, const char *@var{name})Return the address in the module @var{handle}, where the symbol givenby the null-terminated string @var{name} is loaded.If the symbol cannot be found, @code{NULL} is returned.@end deftypefun@deftypefun {const char *} lt_dlerror (void)Return a human readable string describing the mostrecent error that occurred from any of libltdl's functions.Return @code{NULL} if no errors have occurred since initializationor since it was last called.@end deftypefun@deftypefun int lt_dlpreload (const lt_dlsymlist *@var{preloaded})Register the list of preloaded modules @var{preloaded}.If @var{preloaded} is @code{NULL}, then all previously registeredsymbol lists, except the list set by @code{lt_dlpreload_default},are deleted. Return 0 on success.@end deftypefun@deftypefun int lt_dlpreload_default (const lt_dlsymlist *@var{preloaded})Set the default list of preloaded modules to @var{preloaded}, whichwon't be deleted by @code{lt_dlpreload}. Note that this function does@emph{not} require libltdl to be initialized using @code{lt_dlinit} andcan be used in the program to register the default preloaded modules.Instead of calling this function directly, most programs will use themacro @code{LTDL_SET_PRELOADED_SYMBOLS}.Return 0 on success.@end deftypefun@defmac LTDL_SET_PRELOADED_SYMBOLSSet the default list of preloaded symbols.Should be used in your program to initialize libltdl'slist of preloaded modules.@example#include <ltdl.h>int main() @{/* ... */LTDL_SET_PRELOADED_SYMBOLS();/* ... */@}@end example@end defmac@deftypefun int lt_dladdsearchdir (const char *@var{search_dir})Append the search directory @var{search_dir} to the current user-definedlibrary search path. Return 0 on success.@end deftypefun@deftypefun int lt_dlinsertsearchdir (@w{const char *@var{before}}, @w{const char *@var{search_dir}})Insert the search directory @var{search_dir} into the user-defined librarysearch path, immediately before the element starting at address@var{before}. If @var{before} is @samp{NULL}, then @var{search_dir} isappending as if @code{lt_dladdsearchdir} had been called. Return 0 on success.@end deftypefun@deftypefun int lt_dlsetsearchpath (const char *@var{search_path})Replace the current user-defined library search path with@var{search_path}, which must be a colon-separated list of absolutedirectories. Return 0 on success.@end deftypefun@deftypefun {const char *}lt_dlgetsearchpath (void)Return the current user-defined library search path.@end deftypefun@deftypefun int lt_dlforeachfile (@w{const char *@var{search_path}}, @w{int (*@var{func}) (const char *@var{filename}, lt_ptr @var{data})}, @w{lt_ptr @var{data}})In some applications you may not want to load individual modules withknown names, but rather find all of the modules in a set ofdirectories and load them all during initialisation. With this functionyou can have libltdl scan the colon delimited directory list in@var{search_path} for candidates, and pass them, along with @var{data}to your own callback function, @var{func}. If @var{seach_path} is@samp{NULL}, then search all of the standard locations that@code{lt_dlopen} would examine. This function will continue to makecalls to @var{func} for each file that it discovers in @var{search_path}until one of these calls returns non-zero, or until the files areexhausted. @samp{lt_dlforeachfile} returns value returned by the lastcall made to @var{func}.For example you could define @var{func} to build an ordered@dfn{argv}-like vector of files using @var{data} to hold the address ofthe start of the vector.@end deftypefun@deftypefun int lt_dlmakeresident (lt_dlhandle @var{handle})Mark a module so that it cannot be @samp{lt_dlclose}d. This can beuseful if a module implements some core functionality in your project,which would cause your code to crash if removed. Return 0 on success.If you use @samp{lt_dlopen (NULL)} to get a @var{handle} for the runningbinary, that handle will always be marked as resident, and consequentlycannot be successfully @samp{lt_dlclose}d.@end deftypefun@deftypefun int lt_dlisresident (lt_dlhandle @var{handle})Check whether a particular module has been marked as resident, returning 1if it has or 0 otherwise. If there is an error while executing thisfunction, return -1 and set an error message for retrieval with@code{lt_dlerror}.@end deftypefun@deftypevar {lt_ptr (*) (size_t @var{size})} lt_dlmalloc@deftypevarx {lt_ptr (*) (lt_ptr @var{ptr}, size_t @var{size})} lt_dlrealloc@deftypevarx {void (*) (lt_ptr @var{ptr})} lt_dlfreeThese variables are set to @code{malloc}, @code{realloc} and @code{free} bydefault, but you can set them to any other functions that provide equivalentfunctionality. If you change any of these function pointers, you will almostcertainly need to change all three to point into the same malloc library.Strange things will happen if you allocate memory from one library, and thenpass it to an implementation of @code{free} that doesn't know what bookkeeping the allocator used.You must not modify any of their values after calling any libltdl functionother than @code{lt_dlpreopen_default} or the macro@code{LTDL_SET_PRELOADED_SYMBOLS}.@end deftypevar@node Modules for libltdl@section Creating modules that can be @code{dlopen}edLibtool modules are like normal libtool libraries with a few exceptions:You have to link the module with libtool's @samp{-module} switch,and you should link any program that is intended to dlopen the module with@samp{-dlopen modulename.la} so that libtool can dlpreopen the moduleon platforms which don't support dlopening. If the module depends on anyother libraries, make sure you specify them either when you link the moduleor when you link programs that dlopen it.If you want to disable @pxref{Versioning} for a specific moduleyou should link it with the @samp{-avoid-version} switch.Note that libtool modules don't need to have a "lib" prefix.However, automake 1.4 or higher is required to build such modules.Usually a set of modules provide the same interface, i.e, exports the samesymbols, so that a program can dlopen them without having to know moreabout their internals.In order to avoid symbol conflicts all exported symbols must be prefixedwith "modulename_LTX_" (@samp{modulename} is the name of the module).Internal symbols must be named in such a way that they won't conflictwith other modules, for example, by prefixing them with "_modulename_".Although some platforms support having the same symbols defined more thanonce it is generally not portable and it makes it impossible to dlpreopensuch modules. libltdl will automatically cut the prefix off to getthe real name of the symbol. Additionally, it supports modules whichdon't use a prefix so that you can also dlopen non-libtool modules.@file{foo1.c} gives an example of a portable libtool module.Exported symbols are prefixed with "foo1_LTX_", internal symbolswith "_foo1_". Aliases are defined at the beginning so that the codeis more readable.@example/* aliases for the exported symbols */#define foo foo1_LTX_foo#define bar foo1_LTX_bar/* a global variable definition */int bar = 1;/* a private function */int _foo1_helper() @{return bar;@}/* an exported function */int foo() @{return _foo1_helper();@}@end example@noindentThe @file{Makefile.am} contains the necessary rules to build themodule @file{foo1.la}:@example...lib_LTLIBRARIES = foo1.lafoo1_la_SOURCES = foo1.cfoo1_la_LDFLAGS = -module...@end example@node Thread Safety in libltdl@section Using libtldl in a multi threaded environmentUsing the @code{lt_dlmutex_register()} function, and by providing someappropriate callback function definitions, libltdl can be used in amulti-threaded environment.@deftypefn {Type} void lt_dlmutex_lock (void)This is the type of a function pointer holding the address of a functionwhich will be called at the start of parts of the libltdl implementationcode which require a mutex lock.Because libltdl is inherantly recursive, it is important that thelocking mechanism employed by these callback functions are reentrant, orelse strange problems will occur.@end deftypefn@deftypefn {Type} void lt_dlmutex_unlock (void)The type of a matching unlock function.@end deftypefn@deftypefn {Type} void lt_dlmutex_seterror @w{(const char *@var{error});}Many of the functions in the libltdl @sc{api} have a special returnvalue to indicate to the client that an error has occurred. Normally (insingle threaded applications) a string describing that error can beretrieved from internal storage with @code{lt_dlerror()}.A function of this type must be registered with the library in order forit to work in a multi-threaded context. The function should store anyerror message passed in thread local storage.@end deftypefn@deftypefn {Type} {const char *} lt_dlmutex_geterror (void)The type of a matching callback function to retrieve the last storederror message from thread local storage.When regeistered correctly this function will be used by@code{lt_dlerror())} from all threads to retrieve error messages for theclient.@end deftypefn@deftypefn {Function} int lt_dlmutex_register (@w{lt_dlmutex_lock *@var{lock}}, @w{lt_dlmutex_unlock *@var{unlock}}, @w{lt_dlmutex_set_error *@var{seterror}}, @w{lt_dlmutex_geterror *@var{geterror})}Use this function to register one of each of function ttypes describedabove in preparation for multi-threaded use of libltdl. All argumentsmust be valid non-@code{NULL} function addresses, or else all@code{NULL} to return to single threaded operation.@end deftypefn@node User defined module data@section Data associated with loaded modulesSome of the internal information about each loaded module that ismaintained by libltdl is available to the user, in the form of thisstructure:@deftypefn {Type} {struct} lt_dlinfo @{ @w{char *@var{filename};} @w{char *@var{name};} @w{int @var{ref_count};} @}@code{lt_dlinfo} is used to store information about a module.The @var{filename} attribute is a null-terminated character string ofthe real module file name. If the module is a libtool module then@var{name} is its module name (e.g. @code{"libfoo"} for@code{"dir/libfoo.la"}), otherwise it is set to @code{NULL}. The@var{ref_count} attribute is a reference counter that describes howoften the same module is currently loaded.@end deftypefnThe following function will return a pointer to libltdl's internal copyof this structure for the given @var{handle}:@deftypefun {const lt_dlinfo *} lt_dlgetinfo (@w{lt_dlhandle @var{handle}})Return a pointer to a struct that contains some information aboutthe module @var{handle}. The contents of the struct must not be modified.Return @code{NULL} on failure.@end deftypefunFurthermore, in order to save you from having to keep a list of thehandles of all the modules you have loaded, these functions allow you toiterate over libltdl's list of loaded modules:@deftypefun int lt_dlforeach (@w{int (*@var{func}) (lt_dlhandle @var{handle}, lt_ptr @var{data})}, @w{lt_ptr @var{data}})For each loaded module call the function @var{func}. The argument@var{handle} is the handle of one of the loaded modules, @var{data} isthe @var{data} argument passed to @code{lt_dlforeach}.As soon as @var{func} returns a non-zero value for one of the handles,@code{lt_dlforeach} will stop calling @var{func} and immediately return 1.Otherwise 0 is returned.@end deftypefun@deftypefun lt_dlhandle lt_dlhandle_next (@w{lt_dlhandle place})Iterate over the loaded module handles, returning the first handle in thelist if @var{place} is @code{NULL}, and the next one on subsequent calls.If @var{place} is the last element in the list of loaded modules, thisfunction returns @code{NULL}.@end deftypefunOf course, you would still need to maintain your own list of loadedmodule handles to parallel the list maintained by libltdl if there areany other data that you need to associate with each handle for thepurposes of your application. However, if you use the following@sc{api} calls to associate your application data with individual modulehandles as they are loaded there is actually no need to do that. Youmust first obtain a unique caller id from libltdl which you subsequentlyuse to retrieve the data you stored earlier. This allows for differentlibraries that each wish to store their own data against loaded modulesto do so without interfering with one another's data.@deftp {Type} lt_dlcaller_idThe opaque type used to hold individual data set keys.@end deftp@deftypefun lt_dlcaller_id lt_dlcaller_register (void)Use this to obtain a unique key to store and retrieve individual sets ofper module data.@end deftypefun@deftypefun lt_ptr lt_dlcaller_set_data (@w{lt_dlcaller_id @var{key}}, @w{lt_dlhandle @var{handle}}, @w{lt_ptr @var{data}})Set @var{data} as the set of data uniquely associated with @var{key} and@var{handle} for later retrieval. This function returns the @var{data}previously associated with @var{key} and @var{handle} if any. A result of0, may indicate that a diagnostic for the last error (if any) is availablefrom @code{lt_dlerror()}.For example, to correctly remove some associated data:@examplelt_ptr stale = lt_dlcaller_set_data (key, handle, 0);if (stale == NULL)@{char *error_msg = lt_dlerror ();if (error_msg != NULL)@{my_error_handler (error_msg);return STATUS_FAILED;@}@}else@{free (stale);@}@end example@end deftypefun@deftypefun lt_ptr lt_dlcaller_get_data (@w{lt_dlcaller_id @var{key}}, @w{lt_dlhandle @var{handle}})Return the address of the data associated with @var{key} and@var{handle}, or else @code{NULL} if there is none.@end deftypefunThe preceding functions can be combined with @code{lt_dlforeach} toimplement search and apply operations without the need for yourapplication to track the modules that have been loaded and unloaded:@exampleintmy_dlcaller_callback (lt_dlhandle handle, lt_ptr key_ptr)@{struct my_module_data *my_data;my_data = lt_dlcaller_get_data (handle, (lt_dlcaller_id) *key_ptr);return process (my_data);@}intmy_dlcaller_foreach (lt_dlcaller_id key)@{lt_dlforeach (my_dlcaller_callback, (lt_ptr) &key);@}@end example@node Module loaders for libltdl@section How to create and register new module loadersSometimes libltdl's many ways of gaining access to modules are notsufficient for the purposes of a project. You can write your ownloader, and register it with libltdl so that @code{lt_dlopen} will beable to use it.Writing a loader involves writing at least three functions which can becalled by @code{lt_dlopen}, @code{lt_dlsym} and @code{lt_dlclose}.Optionally, you can provide a finalisation function to perform anycleanup operations when @code{lt_dlexit} executes, and a symbol prefixstring which will be prepended to any symbols passed to @code{lt_dlsym}.These functions must match the function pointer types below, afterwhich they can be allocated to an instance of @code{lt_user_dlloader}and registered.Registering the loader requires that you choose a name for it, so that itcan be recognised by @code{lt_dlloader_find} and removed with@code{lt_dlloader_remove}. The name you choose must be unique, and notalready in use by libltdl's builtin loaders:@table @asis@item "dlopen"The system dynamic library loader, if one exists.@item "dld"The @sc{gnu} dld loader, if @file{libdld} was installed when libltdl wasbuilt.@item "dlpreload"The loader for @code{lt_dlopen}ing of preloaded static modules.@end tableThe prefix "dl" is reserved for loaders supplied with future versions oflibltdl, so you should not use that for your own loader names.@noindentThe following types are defined in @file{ltdl.h}:@deftp {Type} lt_module@code{lt_module} is a dlloader dependent module.The dynamic module loader extensions communicate using these lowlevel types.@end deftp@deftp {Type} lt_dlloader@code{lt_dlloader} is a handle for module loader types.@end deftp@deftp {Type} lt_user_data@code{lt_user_data} is used for specifying loader instance data.@end deftp@deftypefn {Type} {struct} lt_user_dlloader @{@w{const char *@var{sym_prefix};} @w{lt_module_open *@var{module_open};} @w{lt_module_close *@var{module_close};} @w{lt_find_sym *@var{find_sym};} @w{lt_dlloader_exit *@var{dlloader_exit};} @}If you want to define a new way to open dynamic modules, and have the@code{lt_dlopen} @sc{api} use it, you need to instantiate one of thesestructures and pass it to @code{lt_dlloader_add}. You can pass whateveryou like in the @var{dlloader_data} field, and it will be passed back asthe value of the first parameter to each of the functions specified inthe function pointer fields.@end deftypefn@deftypefn {Type} lt_module lt_module_open (@w{const char *@var{filename}})The type of the loader function for an @code{lt_dlloader} moduleloader. The value set in the dlloader_data field of the @code{structlt_user_dlloader} structure will be passed into this function in the@var{loader_data} parameter. Implementation of such a function shouldattempt to load the named module, and return an @code{lt_module}suitable for passing in to the associated @code{lt_module_close} and@code{lt_sym_find} function pointers. If the function fails it shouldreturn @code{NULL}, and set the error message with @code{lt_dlseterror}.@end deftypefn@deftypefn {Type} int lt_module_close (@w{lt_user_data @var{loader_data},} @w{lt_module @var{module}})The type of the unloader function for a user defined module loader.Implementatation of such a function should attempt to releaseany resources tied up by the @var{module} module, and then unload itfrom memory. If the function fails for some reason, set the errormessage with @code{lt_dlseterror} and return non-zero.@end deftypefn@deftypefn {Type} lt_ptr lt_find_sym (@w{lt_module @var{module},} @w{const char *@var{symbol}})The type of the symbol lookup function for a user defined module loader.Implementation of such a function should return the address of the named@var{symbol} in the module @var{module}, or else set the error messagewith @code{lt_dlseterror} and return @code{NULL} if lookup fails.@end deftypefn@deftypefn {Type} int lt_dlloader_exit (@w{lt_user_data @var{loader_data}})The type of the finalisation function for a user defined module loader.Implementation of such a function should free any resources associatedwith the loader, including any user specified data in the@code{dlloader_data} field of the @code{lt_user_dlloader}. If non-@code{NULL},the function will be called by @code{lt_dlexit}, and@code{lt_dlloader_remove}.@end deftypefnFor example:@exampleintregister_myloader (void)@{lt_user_dlloader dlloader;/* User modules are responsible for their own initialisation. */if (myloader_init () != 0)return MYLOADER_INIT_ERROR;dlloader.sym_prefix = NULL;dlloader.module_open = myloader_open;dlloader.module_close = myloader_close;dlloader.find_sym = myloader_find_sym.dlloader.dlloader_exit = myloader_exit;dlloader.dlloader_data = (lt_user_data)myloader_function;/* Add my loader as the default module loader. */if (lt_dlloader_add (lt_dlloader_next (NULL), &dlloader, "myloader") \!= 0)return ERROR;return OK;@}@end exampleNote that if there is any initialisation required for the loader,it must be performed manually before the loader is registered --libltdl doesn't handle user loader initialisation.Finalisation @emph{is} handled by libltdl however, and it is importantto ensure the @code{dlloader_exit} callback releases any resources claimedduring the initialisation phase.@page@noindentlibltdl provides the following functions for writing your own moduleloaders:@deftypefun int lt_dlloader_add (@w{lt_dlloader *@var{place},} @w{lt_user_dlloader *@var{dlloader},} @w{const char *@var{loader_name}})Add a new module loader to the list of all loaders, either as thelast loader (if @var{place} is @code{NULL}), else immediately before theloader passed as @var{place}. @var{loader_name} will be returned by@code{lt_dlloader_name} if it is subsequently passed a newlyregistered loader. These @var{loader_name}s must be unique, or@code{lt_dlloader_remove} and @code{lt_dlloader_find} cannotwork. Returns 0 for success.@example@{/* Make myloader be the last one. */if (lt_dlloader_add (NULL, myloader) != 0)perror (lt_dlerror ());@}@end example@end deftypefun@deftypefun int lt_dlloader_remove (@w{const char *@var{loader_name}})Remove the loader identified by the unique name, @var{loader_name}.Before this can succeed, all modules opened by the named loader musthave been closed. Returns 0 for success, otherwise an error message canbe obtained from @code{lt_dlerror}.@example@{/* Remove myloader. */if (lt_dlloader_remove ("myloader") != 0)perror (lt_dlerror ());@}@end example@end deftypefun@deftypefun {lt_dlloader *}lt_dlloader_next (@w{lt_dlloader *@var{place}})Iterate over the module loaders, returning the first loader if @var{place} is@code{NULL}, and the next one on subsequent calls. The handle is for use with@code{lt_dlloader_add}.@example@{/* Make myloader be the first one. */if (lt_dlloader_add (lt_dlloader_next (NULL), myloader) != 0)return ERROR;@}@end example@end deftypefun@deftypefun {lt_dlloader *}lt_dlloader_find (@w{const char *@var{loader_name}})Return the first loader with a matching @var{loader_name} identifier, or else@code{NULL}, if the identifier is not found.The identifiers which may be used by libltdl itself, if the hostarchitecture supports them are @dfn{dlopen}@footnote{This is used forthe host dependent module loading @sc{api} -- @code{shl_load} and@code{LoadLibrary} for example}, @dfn{dld} and @dfn{dlpreload}.@example@{/* Add a user loader as the next module loader to be tried ifthe standard dlopen loader were to fail when lt_dlopening. */if (lt_dlloader_add (lt_dlloader_find ("dlopen"), myloader) != 0)return ERROR;@}@end example@end deftypefun@deftypefun {const char *}lt_dlloader_name (@w{lt_dlloader *@var{place}})Return the identifying name of @var{PLACE}, as obtained from@code{lt_dlloader_next} or @code{lt_dlloader_find}. If this function fails,it will return @code{NULL} and set an error for retrieval with@code{lt_dlerror}.@end deftypefun@deftypefun {lt_user_data *}lt_dlloader_data (@w{lt_dlloader *@var{place}})Return the address of the @code{dlloader_data} of @var{PLACE}, asobtained from @code{lt_dlloader_next} or @code{lt_dlloader_find}. Ifthis function fails, it will return @code{NULL} and set an error forretrieval with @code{lt_dlerror}.@end deftypefun@subsection Error handling within user module loaders@deftypefun int lt_dladderror (@w{const char *@var{diagnostic}})This function allows you to integrate your own error messages into@code{lt_dlerror}. Pass in a suitable diagnostic message for return by@code{lt_dlerror}, and an error identifier for use with@code{lt_dlseterror} is returned.If the allocation of an identifier fails, this function returns -1.@exampleint myerror = lt_dladderror ("Doh!");if (myerror < 0)perror (lt_dlerror ());@end example@end deftypefun@deftypefun int lt_dlseterror (@w{int @var{errorcode}})When writing your own module loaders, you should use this function toraise errors so that they are propogated through the @code{lt_dlerror}interface. All of the standard errors used by libltdl are declared in@file{ltdl.h}, or you can add more of your own with@code{lt_dladderror}. This function returns 0 on success.@exampleif (lt_dlseterror (LTDL_ERROR_NO_MEMORY) != 0)perror (lt_dlerror ());@end example@end deftypefun@node Distributing libltdl@section How to distribute libltdl with your packageEven though libltdl is installed together with libtool, you may wish toinclude libltdl in the distribution of your package, for the convenienceof users of your package that don't have libtool or libltdl installed.In this case, you must decide whether to manually add the @code{ltdl}objects to your package, or else which flavor of libltdl you want to use:a convenience library or an installable libtool library.The most simplistic way to add @code{libltdl} to your package is to copythe source files, @file{ltdl.c} and @file{ltdl.h}, to a source directorywithin your package and to build and link them along with the rest ofyour sources. To help you do this, the m4 macros for autoconf areavailable in @file{ltdl.m4}. You must ensure that they are available in@file{aclocal.m4} before you run Autoconf -- by appending the contentsof @file{ltdl.m4} to @file{acinclude.m4}, if you are using automake, orto @file{aclocal.m4} if you are not. Having made the macros available,you must add a call to the @samp{AC_LIB_LTDL} macro to your package's@file{configure.in} to perform the configure time checks required tobuild @file{ltdl.o} correctly. This method has problems if you then tryto link the package binaries with an installed libltdl, or a librarywhich depends on libltdl: you may have problems with duplicate symboldefinitions.One advantage of the convenience library is that it is not installed, sothe fact that you use libltdl will not be apparent to the user, and itwill not overwrite a pre-installed version of libltdl a user might have.On the other hand, if you want to upgrade libltdl for any reason(e.g. a bugfix) you'll have to recompile your package instead of justreplacing an installed version of libltdl.However, if your programs or libraries are linked with other librariesthat use such a pre-installed version of libltdl, you may get linkererrors or run-time crashes. Another problem is that you cannot link theconvenience library into more than one libtool library, then link asingle program with these libraries, because you may get duplicatesymbols. In general you can safely use the convenience library in programswhich don't depend on other libraries that might use libltdl too.In order to enable this flavor of libltdl, you should add theline @samp{AC_LIBLTDL_CONVENIENCE} to your @file{configure.in},@emph{before} @samp{AC_PROG_LIBTOOL}.In order to select the installable version of libltdl, you should add acall of the macro @samp{AC_LIBLTDL_INSTALLABLE} to your@file{configure.in} @emph{before} @samp{AC_PROG_LIBTOOL}. This macrowill check whether libltdl is already installed and, if not, request thelibltdl embedded in your package to be built and installed. Note,however, that no version checking is performed. The user may overridethe test and determine that the libltdl embedded must be installed,regardless of the existence of another version, using the configureswitch @samp{--enable-ltdl-install}.In order to embed libltdl into your package, just add @samp{--ltdl} tothe @code{libtoolize} command line. It will copy the libltdl sourcesto a subdirectory @samp{libltdl} in your package.Both macros accept an optional argument to specify the locationof the @samp{libltdl} directory. By the default both macros assume that itis @samp{$@{top_srcdir@}/libltdl}.Whatever macro you use, it is up to you to ensure that your@file{configure.in} will configure libltdl, using@samp{AC_CONFIG_SUBDIRS}, and that your @file{Makefile}s will startsub-makes within libltdl's directory, using automake's @var{SUBDIRS},for example. Both macros define the shell variables @var{LIBLTDL}, tothe link flag that you should use to link with libltdl, and@var{LTDLINCL}, to the preprocessor flag that you should use to compilewith programs that include @file{ltdl.h}. It is up to you to use@samp{AC_SUBST} to ensure that this variable will be available in@file{Makefile}s, or add them to variables that are @samp{AC_SUBST}ed bydefault, such as @var{LIBS} and @var{CPPFLAGS}. Also note that you shouldnot include @file{libltdl/Makefile} in the list of files to be configuredfrom your toplevel @file{configure.in}; this is done by@file{libltdl/configure.ac}.If you're using the convenience libltdl, @var{LIBLTDL} will be thepathname for the convenience version of libltdl and @var{LTDLINCL} will be@samp{-I} followed by the directory that contains libltdl, both startingwith @samp{$@{top_builddir@}/} or @samp{$@{top_srcdir@}/}, respectively.If you request an installed version of libltdl and one isfound@footnote{Even if libltdl is installed,@samp{AC_LIBLTDL_INSTALLABLE} may fail to detect it, if libltdl dependson symbols provided by libraries other than the C library. In thiscase, it will needlessly build and install libltdl.}, @var{LIBLTDL} willbe set to @samp{-lltdl} and @var{LTDLINCL} will be empty (which is just ablind assumption that @file{ltdl.h} is somewhere in the include path iflibltdl is in the library path). If an installable version of libltdlmust be built, its pathname, starting with @samp{$@{top_builddir@}/},will be stored in @var{LIBLTDL}, and @var{LTDLINCL} will be set just likein the case of convenience library.So, when you want to link a program with libltdl, be it a convenience,installed or installable library, just compile with @samp{$(LTDLINCL)}and link it with @samp{$(LIBLTDL)}, using libtool.You should probably also add @samp{AC_LIBTOOL_DLOPEN} to your@file{configure.in} @emph{before} @samp{AC_PROG_LIBTOOL}, otherwiselibtool will assume no dlopening mechanism is supported, and revert todlpreopening, which is probably not what you want.Avoid using the @code{-static} or @code{-all-static} switches whenlinking programs with libltdl. This will not work on all platforms,because the dlopening functions may not be available for static linking.The following example shows you how to embed the convenience libltdl inyour package. In order to use the installable variant just replace@samp{AC_LIBLTDL_CONVENIENCE} with @samp{AC_LIBLTDL_INSTALLABLE}. Weassume that libltdl was embedded using @samp{libtoolize --ltdl}.configure.in:@example...dnl Enable building of the convenience librarydnl and set LIBLTDL accordinglyAC_LIBLTDL_CONVENIENCEdnl Check for dlopen supportAC_LIBTOOL_DLOPENdnl Configure libtoolAC_PROG_LIBTOOLdnl Configure libltdlAC_CONFIG_SUBDIRS(libltdl)...@end exampleMakefile.am:@example...SUBDIRS = libltdlINCLUDES = $(LTDLINCL)myprog_LDFLAGS = -export-dynamic# The quotes around -dlopen below fool automake <= 1.4 into accepting itmyprog_LDADD = $(LIBLTDL) "-dlopen" self "-dlopen" foo1.lamyprog_DEPENDENCIES = $(LIBLTDL) foo1.la...@end example@node Other languages@chapter Using libtool with other languages@cindex C, not using@cindex languages, non-C@cindex C++, usingLibtool was first implemented in order to add support for writing sharedlibraries in the C language. However, over time, libtool is beingintegrated with other languages, so that programmers are free to reapthe benefits of shared libraries in their favorite programming language.This chapter describes how libtool interacts with other languages,and what special considerations you need to make if you do not use C.@menu* C++ libraries::@end menu@node C++ libraries@section Writing libraries for C++@c FIXME: in the TOC, the ++ is too large (seems to be math mode)@cindex trouble with C++@cindex pitfalls using C++@cindex C++, pitfallsCreating libraries of C++ code should be a fairly straightforwardprocess, because its object files differ from C ones in only three ways:@enumerate 1@itemBecause of name mangling, C++ libraries are only usable by the C++compiler that created them. This decision was made by the designers ofC++ in order to protect users from conflicting implementations offeatures such as constructors, exception handling, and RTTI.@itemOn some systems, the C++ compiler must take special actions for thedynamic linker to run dynamic (i.e., run-time) initializers. This meansthat we should not call @file{ld} directly to link such libraries, andwe should use the C++ compiler instead.@itemC++ compilers will link some Standard C++ library in by default, butlibtool does not know which are these libraries, so it cannot even runthe inter-library dependence analyzer to check how to link it in.Therefore, running @file{ld} to link a C++ program or library is deemedto fail.@end enumerateBecause of these three issues, Libtool has been designed to always usethe C++ compiler to compile and link C++ programs and libraries. Insome instances the @code{main()} function of a program must also becompiled with the C++ compiler for static C++ objects to be properlyinitialized.@node Troubleshooting@chapter Troubleshooting@cindex troubleshooting@cindex problems, solving@cindex solving problems@cindex problems, blaming somebody else forLibtool is under constant development, changing to remain up-to-datewith modern operating systems. If libtool doesn't work the way youthink it should on your platform, you should read this chapter to helpdetermine what the problem is, and how to resolve it.@menu* Libtool test suite:: Libtool's self-tests.* Reporting bugs:: How to report problems with libtool.@end menu@node Libtool test suite@section The libtool test suite@cindex test suiteLibtool comes with its own set of programs that test its capabilities,and report obvious bugs in the libtool program. These tests, too, areconstantly evolving, based on past problems with libtool, and knowndeficiencies in other operating systems.As described in the @file{INSTALL} file, you may run @kbd{make check}after you have built libtool (possibly before you install it) in orderto make sure that it meets basic functional requirements.@menu* Test descriptions:: The contents of the test suite.* When tests fail:: What to do when a test fails.@end menu@node Test descriptions@subsection Description of test suiteHere is a list of the current programs in the test suite, and what theytest for:@table @file@item cdemo-conf.test@itemx cdemo-exec.test@itemx cdemo-make.test@itemx cdemo-static.test@itemx cdemo-shared.test@pindex cdemo-conf.test@pindex cdemo-exec.test@pindex cdemo-make.test@pindex cdemo-static.test@pindex cdemo-shared.testThese programs check to see that the @file{cdemo} subdirectory of thelibtool distribution can be configured and built correctly.The @file{cdemo} subdirectory contains a demonstration of libtoolconvenience libraries, a mechanism that allows build-time staticlibraries to be created, in a way that their components can be laterlinked into programs or other libraries, even shared ones.The tests @file{cdemo-make.test} and @file{cdemo-exec.test} are executedthree times, under three different libtool configurations:@file{cdemo-conf.test} configures @file{cdemo/libtool} to build bothstatic and shared libraries (the default for platforms that supportboth), @file{cdemo-static.test} builds only static libraries(@samp{--disable-shared}), and @file{cdemo-shared.test} builds onlyshared libraries (@samp{--disable-static}).@item demo-conf.test@itemx demo-exec.test@itemx demo-inst.test@itemx demo-make.test@itemx demo-unst.test@itemx demo-static.test@itemx demo-shared.test@itemx demo-nofast.test@itemx demo-pic.test@itemx demo-nopic.test@pindex demo-conf.test@pindex demo-exec.test@pindex demo-inst.test@pindex demo-make.test@pindex demo-unst.test@pindex demo-static.test@pindex demo-shared.test@pindex demo-nofast.test@pindex demo-pic.test@pindex demo-nopic.testThese programs check to see that the @file{demo} subdirectory of thelibtool distribution can be configured, built, installed, anduninstalled correctly.The @file{demo} subdirectory contains a demonstration of a trivialpackage that uses libtool. The tests @file{demo-make.test},@file{demo-exec.test}, @file{demo-inst.test} and@file{demo-unst.test} are executed four times, under four differentlibtool configurations: @file{demo-conf.test} configures@file{demo/libtool} to build both static and shared libraries,@file{demo-static.test} builds only static libraries(@samp{--disable-shared}), and @file{demo-shared.test} builds onlyshared libraries (@samp{--disable-static}).@file{demo-nofast.test} configures @file{demo/libtool} todisable the fast-install mode (@samp{--enable-fast-install=no}).@file{demo-pic.test} configures @file{demo/libtool} toprefer building PIC code (@samp{--with-pic}), @file{demo-nopic.test}to prefer non-PIC code (@samp{--without-pic}).@item deplibs.test@pindex deplibs.testMany systems cannot link static libraries into shared libraries.libtool uses a @code{deplibs_check_method} to prevent such cases.This tests checks whether libtool's @code{deplibs_check_method}works properly.@item hardcode.test@pindex hardcode.testOn all systems with shared libraries, the location of the library can beencoded in executables that are linked against it @pxref{Linkingexecutables}. This test checks the conditions under which your systemlinker hardcodes the library location, and guarantees that theycorrespond to libtool's own notion of how your linker behaves.@item build-relink.test@pindex build-relink.testChecks whether variable @var{shlibpath_overrides_runpath} is properlyset. If the test fails and @var{VERBOSE} is set, it will indicate whatthe variable should have been set to.@item noinst-link.test@pindex noinst-link.testChecks whether libtool will not try to link with a previously installedversion of a library when it should be linking with a just-built one.@item depdemo-conf.test@itemx depdemo-exec.test@itemx depdemo-inst.test@itemx depdemo-make.test@itemx depdemo-unst.test@itemx depdemo-static.test@itemx depdemo-shared.test@itemx depdemo-nofast.test@pindex depdemo-conf.test@pindex depdemo-exec.test@pindex depdemo-inst.test@pindex depdemo-make.test@pindex depdemo-unst.test@pindex depdemo-static.test@pindex depdemo-shared.test@pindex depdemo-nofast.testThese programs check to see that the @file{depdemo} subdirectory of thelibtool distribution can be configured, built, installed, anduninstalled correctly.The @file{depdemo} subdirectory contains a demonstration of inter-librarydependencies with libtool. The test programs link some interdependentlibraries.The tests @file{depdemo-make.test}, @file{depdemo-exec.test},@file{depdemo-inst.test} and @file{depdemo-unst.test} are executedfour times, under four different libtool configurations:@file{depdemo-conf.test} configures @file{depdemo/libtool} to build bothstatic and shared libraries, @file{depdemo-static.test} builds only staticlibraries (@samp{--disable-shared}), and @file{depdemo-shared.test} buildsonly shared libraries (@samp{--disable-static}).@file{depdemo-nofast.test} configures @file{depdemo/libtool} todisable the fast-install mode (@samp{--enable-fast-install=no}.@item mdemo-conf.test@itemx mdemo-exec.test@itemx mdemo-inst.test@itemx mdemo-make.test@itemx mdemo-unst.test@itemx mdemo-static.test@itemx mdemo-shared.test@pindex mdemo-conf.test@pindex mdemo-exec.test@pindex mdemo-inst.test@pindex mdemo-make.test@pindex mdemo-unst.test@pindex mdemo-static.test@pindex mdemo-shared.testThese programs check to see that the @file{mdemo} subdirectory of thelibtool distribution can be configured, built, installed, anduninstalled correctly.The @file{mdemo} subdirectory contains a demonstration of a package thatuses libtool and the system independent dlopen wrapper @file{libltdl} toload modules. The library @file{libltdl} provides a dlopen wrapper forvarious platforms (Linux, Solaris, HP/UX etc.) including support fordlpreopened modules (@pxref{Dlpreopening}).The tests @file{mdemo-make.test}, @file{mdemo-exec.test},@file{mdemo-inst.test} and @file{mdemo-unst.test} are executedthree times, under three different libtool configurations:@file{mdemo-conf.test} configures @file{mdemo/libtool} to build bothstatic and shared libraries, @file{mdemo-static.test} builds only staticlibraries (@samp{--disable-shared}), and @file{mdemo-shared.test} buildsonly shared libraries (@samp{--disable-static}).@item dryrun.test@pindex dryrun.testThis test checks whether libtool's @code{--dry-run} mode works properly.@item assign.test@pindex assign.testChecks whether we don't put break or continue on the sameline as an assignment in the libtool script.@item link.test@pindex link.testThis test guarantees that linking directly against a non-libtool staticlibrary works properly.@item link-2.test@pindex link-2.testThis test makes sure that files ending in @samp{.lo} are never linkeddirectly into a program file.@item nomode.test@pindex nomode.testCheck whether we can actually get help for libtool.@item quote.test@pindex quote.testThis program checks libtool's metacharacter quoting.@item sh.test@pindex sh.testChecks whether a `test' command was forgotten in libtool.@item suffix.test@pindex suffix.testWhen other programming languages are used with libtool (@pxref{Otherlanguages}), the source files may end in suffixes other than @samp{.c}.This test validates that libtool can handle suffixes for all the filetypes that it supports, and that it fails when the suffix is invalid.@end table@node When tests fail@subsection When tests fail@cindex failed tests@cindex tests, failedEach of the above tests are designed to produce no output when they arerun via @kbd{make check}. The exit status of each program tells the@file{Makefile} whether or not the test succeeded.If a test fails, it means that there is either a programming error inlibtool, or in the test program itself.To investigate a particular test, you may run it directly, as you woulda normal program. When the test is invoked in this way, it producesoutput which may be useful in determining what the problem is.Another way to have the test programs produce output is to set the@var{VERBOSE} environment variable to @samp{yes} before running them.For example, @kbd{env VERBOSE=yes make check} runs all the tests, andhas each of them display debugging information.@node Reporting bugs@section Reporting bugs@cindex bug reports@cindex reporting bugs@cindex problem reportsIf you think you have discovered a bug in libtool, you should thinktwice: the libtool maintainer is notorious for passing the buck (ormaybe that should be ``passing the bug''). Libtool was invented to fixknown deficiencies in shared library implementations, so, in a way, mostof the bugs in libtool are actually bugs in other operating systems.However, the libtool maintainer would definitely be happy to add supportfor somebody else's buggy operating system. [I wish there was a goodway to do winking smiley-faces in Texinfo.]Genuine bugs in libtool include problems with shell script portability,documentation errors, and failures in the test suite (@pxref{Libtooltest suite}).First, check the documentation and help screens to make sure that thebehaviour you think is a problem is not already mentioned as a feature.Then, you should read the Emacs guide to reporting bugs (@pxref{Bugs, ,Reporting Bugs, emacs, The Emacs Manual}). Some of the detailslisted there are specific to Emacs, but the principle behind them is ageneral one.Finally, send a bug report to @value{BUGADDR} with any appropriate@emph{facts}, such as test suite output (@pxref{When tests fail}), allthe details needed to reproduce the bug, and a brief description of whyyou think the behaviour is a bug. Be sure to include the word``libtool'' in the subject line, as well as the version number you areusing (which can be found by typing @kbd{libtool --version}).@node Maintaining@chapter Maintenance notes for libtoolThis chapter contains information that the libtool maintainer findsimportant. It will be of no use to you unless you are consideringporting libtool to new systems, or writing your own libtool.@menu* New ports:: How to port libtool to new systems.* Tested platforms:: When libtool was last tested.* Platform quirks:: Information about different library systems.* libtool script contents:: Configuration information that libtool uses.* Cheap tricks:: Making libtool maintainership easier.@end menu@node New ports@section Porting libtool to new systemsBefore you embark on porting libtool to an unsupported system, it isworthwhile to send e-mail to @value{MAILLIST}, to make sure that you arenot duplicating existing work.If you find that any porting documentation is missing, please complain!Complaints with patches and improvements to the documentation, or tolibtool itself, are more than welcome.@menu* Information sources:: Where to find relevant documentation* Porting inter-library dependencies:: Implementation details explained@end menu@node Information sources@subsection Information sourcesOnce it is clear that a new port is necessary, you'll generally need thefollowing information:@table @asis@item canonical system nameYou need the output of @code{config.guess} for this system, so that youcan make changes to the libtool configuration process without affectingother systems.@item man pages for @code{ld} and @code{cc}These generally describe what flags are used to generate PIC, to createshared libraries, and to link against only static libraries. You mayneed to follow some cross references to find the information that isrequired.@item man pages for @code{ld.so}, @code{rtld}, or equivalentThese are a valuable resource for understanding how shared libraries areloaded on the system.@item man page for @code{ldconfig}, or equivalentThis page usually describes how to install shared libraries.@item output from @kbd{ls -l /lib /usr/lib}This shows the naming convention for shared libraries on the system,including which names should be symbolic links.@item any additional documentationSome systems have special documentation on how to build and installshared libraries.@end tableIf you know how to program the Bourne shell, then you can complete theport yourself; otherwise, you'll have to find somebody with the relevantskills who will do the work. People on the libtool mailing list areusually willing to volunteer to help you with new ports, so you can sendthe information to them.To do the port yourself, you'll definitely need to modify the@code{libtool.m4} macros in order to make platform-specific changes tothe configuration process. You should search that file for the@code{PORTME} keyword, which will give you some hints on what you'llneed to change. In general, all that is involved is modifying theappropriate configuration variables (@pxref{libtool script contents}).Your best bet is to find an already-supported system that is similar toyours, and make your changes based on that. In some cases, however,your system will differ significantly from every other supported system,and it may be necessary to add new configuration variables, and modifythe @code{ltmain.in} script accordingly. Be sure to write to themailing list before you make changes to @code{ltmain.in}, since they mayhave advice on the most effective way of accomplishing what you want.@node Porting inter-library dependencies@subsection Porting inter-library dependencies support@cindex inter-library dependency@vindex deplibs_check_methodSince version 1.2c, libtool has re-introduced the ability to dointer-library dependency on some platforms, thanks to a patch by ToshioKuratomi @email{badger@@prtr-13.ucsc.edu}. Here's a shortened versionof the message that contained his patch:The basic architecture is this: in @file{libtool.m4}, the person whowrites libtool makes sure @samp{$deplibs} is included in@samp{$archive_cmds} somewhere and also sets the variable@samp{$deplibs_check_method}, and maybe @samp{$file_magic_cmd} when@samp{deplibs_check_method} is file_magic.@samp{deplibs_check_method} can be one of five things:@table @samp@item file_magic [@var{regex}]@vindex file_magic@vindex file_magic_cmd@vindex file_magic_test_filelooks in the library link path for libraries that have the rightlibname. Then it runs @samp{$file_magic_cmd} on the library and checksfor a match against the extended regular expression @var{regex}. When@var{file_magic_test_file} is set by @file{libtool.m4}, it is used as anargument to @samp{$file_magic_cmd} in order to verify whether theregular expression matches its output, and warn the user otherwise.@item test_compile@vindex test_compilejust checks whether it is possible to link a program out of a list oflibraries, and checks which of those are listed in the output of@code{ldd}. It is currently unused, and will probably be dropped in thefuture.@item pass_all@vindex pass_allwill pass everything without any checking. This may work on platformsin which code is position-independent by default and inter-librarydependencies are properly supported by the dynamic linker, for example,on DEC OSF/1 3 and 4.@item none@vindex noneIt causes deplibs to be reassigned deplibs="". That way@samp{archive_cmds} can contain deplibs on all platforms, but not havedeplibs used unless needed.@item unknown@vindex unknownis the default for all systems unless overridden in @file{libtool.m4}.It is the same as @samp{none}, but it documents that we really don'tknow what the correct value should be, and we welcome patches thatimprove it.@end tableThen in @file{ltmain.in} we have the real workhorse: a littleinitialization and postprocessing (to setup/release variables for usewith eval echo libname_spec etc.) and a case statement that decideswhich method is being used. This is the real code... I wish I couldcondense it a little more, but I don't think I can without functioncalls. I've mostly optimized it (moved things out of loops, etc) butthere is probably some fat left. I thought I should stop while I wasahead, work on whatever bugs you discover, etc before thinking aboutmore than obvious optimizations.@node Tested platforms@section Tested platformsThis table describes when libtool was last known to be tested onplatforms where it claims to support shared libraries:@example@include PLATFORMS@end exampleNote: The vendor-distributed HP-UX @code{sed}(1) programs are horriblybroken, and cannot handle libtool's requirements, so users may reportunusual problems. There is no workaround except to install a working@code{sed} (such as GNU @code{sed}) on these systems.Note: The vendor-distributed NCR MP-RAS @code{cc} programs emitscopyright on standard error that confuse tests on size of@file{conftest.err}. The workaround is to specify @code{CC}when run @code{configure} with @kbd{CC='cc -Hnocopyr'}.@node Platform quirks@section Platform quirksThis section is dedicated to the sanity of the libtool maintainers. Itdescribes the programs that libtool uses, how they vary from system tosystem, and how to test for them.Because libtool is a shell script, it can be difficult to understandjust by reading it from top to bottom. This section helps show whylibtool does things a certain way. Combined with the scriptsthemselves, you should have a better sense of how to improve libtool, orwrite your own.@menu* References:: Finding more information.* Compilers:: Creating object files from source files.* Reloadable objects:: Binding object files together.* Multiple dependencies:: Removing duplicate dependent libraries.* Archivers:: Programs that create static archives.@end menu@node References@subsection ReferencesThe following is a list of valuable documentation references:@itemize @bullet@itemSGI's IRIX Manual Pages, which can be found at@url{http://techpubs.sgi.com/cgi-bin/infosrch.cgi?cmd=browse&db=man}.@itemSun's free service area(@url{http://www.sun.com/service/online/free.html}) and documentationserver (@url{http://docs.sun.com/}).@itemCompaq's Tru64 UNIX online documentation is at @*(@url{http://tru64unix.compaq.com/faqs/publications/pub_page/doc_list.html})with C++ documentation at @*(@url{http://tru64unix.compaq.com/cplus/docs/index.htm}).@itemHewlett-Packard has online documentation at(@url{http://docs.hp.com/index.html}).@itemIBM has online documentation at(@url{http://www.rs6000.ibm.com/resource/aix_resource/Pubs/}).@end itemize@node Compilers@subsection CompilersThe only compiler characteristics that affect libtool are the flagsneeded (if any) to generate PIC objects. In general, if a C compilersupports certain PIC flags, then any derivative compilers support thesame flags. Until there are some noteworthy exceptions to this rule,this section will document only C compilers.The following C compilers have standard command line options, regardlessof the platform:@table @code@item gccThis is the GNU C compiler, which is also the system compiler for manyfree operating systems (FreeBSD, GNU/Hurd, GNU/Linux, Lites, NetBSD, andOpenBSD, to name a few).The @samp{-fpic} or @samp{-fPIC} flags can be used to generateposition-independent code. @samp{-fPIC} is guaranteed to generateworking code, but the code is slower on m68k, m88k, and Sparc chips.However, using @samp{-fpic} on those chips imposes arbitrary size limitson the shared libraries.@end tableThe rest of this subsection lists compilers by the operating system thatthey are bundled with:@c FIXME these should all be better-documented@table @code@item aix3*@itemx aix4*Most AIX compilers have no PIC flags, since AIX (with the exception ofAIX for IA-64) runs on PowerPC and RS/6000 chips. @footnote{All code compiledfor the PowerPC and RS/6000 chips (@code{powerpc-*-*}, @code{powerpcle-*-*},and @code{rs6000-*-*}) is position-independent, regardless of the operatingsystem or compiler suite. So, ``regular objects'' can be used to buildshared libraries on these systems and no special PIC compiler flags arerequired.}@item hpux10*Use @samp{+Z} to generate PIC.@item osf3*Digital/UNIX 3.x does not have PIC flags, at least not on the PowerPCplatform.@item solaris2*Use @samp{-KPIC} to generate PIC.@item sunos4*Use @samp{-PIC} to generate PIC.@end table@node Reloadable objects@subsection Reloadable objectsOn all known systems, a reloadable object can be created by running@kbd{ld -r -o @var{output}.o @var{input1}.o @var{input2}.o}. Thisreloadable object may be treated as exactly equivalent to otherobjects.@node Multiple dependencies@subsection Multiple dependenciesOn most modern platforms the order that dependent libraries are listedhas no effect on object generation. In theory, there are platformswhich require libraries which provide missing symbols to other librariesto listed after those libraries whose symbols they provide.Particularly, if a pair of static archives each resolve some of theother's symbols, it might be necessary to list one of those archivesboth before and after the other one. Libtool does not currently copewith this situation well, since duplicate libraries are removed fromthe link line by default. Libtool provides the command line option@samp{--preserve-dup-deps} to preserve all duplicate dependenciesin cases where it is necessary.@node Archivers@subsection ArchiversOn all known systems, building a static library can be accomplished byrunning @kbd{ar cru lib@var{name}.a @var{obj1}.o @var{obj2}.o @dots{}},where the @samp{.a} file is the output library, and each @samp{.o} file is anobject file.On all known systems, if there is a program named @code{ranlib}, then itmust be used to ``bless'' the created library before linking against it,with the @kbd{ranlib lib@var{name}.a} command. Some systems, like Irix,use the @code{ar ts} command, instead.@node libtool script contents@section @code{libtool} script contents@cindex implementation of libtool@cindex libtool implementationSince version 1.4, the @code{libtool} script is generated by@code{configure} (@pxref{Configuring}). In earlier versions,@code{configure} achieved this by calling a helper script called@file{ltconfig}. From libtool version 0.7 to 1.0, this scriptsimply set shell variables, then sourced the libtool backend,@code{ltmain.sh}. @code{ltconfig} from libtool version 1.1 through 1.3inlined the contents of @code{ltmain.sh} into the generated@code{libtool}, which improved performance on many systems. The teststhat @file{ltconfig} used to perform are now kept in @file{libtool.m4}where thay can be written using Autoconf. This has the runtimeperformance benefits of inlined @code{ltmain.sh}, @emph{and} improvesthe build time a little while considerably easing the amount of rawshell code that used to need maintaining.The convention used for naming variables which hold shell commands fordelayed evaluation, is to use the suffix @code{_cmd} where a singleline of valid shell script is needed, and the suffix @code{_cmds} wheremultiple lines of shell script @strong{may} be delayed for laterevaluation. By convention, @code{_cmds} variables delimit theevaluation units with the @code{~} character where necessary.Here is a listing of each of the configuration variables, and how theyare used within @code{ltmain.sh} (@pxref{Configuring}):@defvar ARThe name of the system library archiver.@end defvar@defvar CCThe name of the C compiler used to configure libtool.@end defvar@defvar LDThe name of the linker that libtool should use internally for reloadablelinking and possibly shared libraries.@end defvar@defvar NMThe name of a BSD-compatible @code{nm} program, which produces listingsof global symbols in one the following formats:@example@var{address} C @var{global-variable-name}@var{address} D @var{global-variable-name}@var{address} T @var{global-function-name}@end example@end defvar@defvar RANLIBSet to the name of the ranlib program, if any.@end defvar@defvar allow_undefined_flagThe flag that is used by @samp{archive_cmds} in order to declare thatthere will be unresolved symbols in the resulting shared library.Empty, if no such flag is required. Set to @samp{unsupported} if thereis no way to generate a shared library with references to symbols thataren't defined in that library.@end defvar@defvar always_export_symbolsWhether libtool should automatically generate a list of exported symbolsusing @var{export_symbols_cmds} before linking an archive.Set to @samp{yes} or @samp{no}. Default is @samp{no}.@end defvar@defvar archive_cmds@defvarx archive_expsym_cmds@defvarx old_archive_cmdsCommands used to create shared libraries, shared libraries with@samp{-export-symbols} and static libraries, respectively.@end defvar@defvar old_archive_from_new_cmdsIf the shared library depends on a static library,@samp{old_archive_from_new_cmds} contains the commands used to create thatstatic library. If this variable is not empty, @samp{old_archive_cmds} isnot used.@end defvar@defvar old_archive_from_expsyms_cmdsIf a static library must be created from the export symbol list in order tocorrectly link with a shared library, @samp{old_archive_from_expsyms_cmds}contains the commands needed to create that static library. When thesecommands are executed, the variable @var{soname} contains the name of theshared library in question, and the @var{$objdir/$newlib} contains thepath of the static library these commands should build. After executingthese commands, libtool will proceed to link against @var{$objdir/$newlib}instead of @var{soname}.@end defvar@defvar build_libtool_libsWhether libtool should build shared libraries on this system. Set to@samp{yes} or @samp{no}.@end defvar@defvar build_old_libsWhether libtool should build static libraries on this system. Set to@samp{yes} or @samp{no}.@end defvar@defvar compiler_c_oWhether the compiler supports the @code{-c} and @code{-o} optionssimultaneously. Set to @samp{yes} or @samp{no}.@end defvar@defvar compiler_o_loWhether the compiler supports compiling directly to a ".lo" file,i.e whether object files do not have to have the suffix ".o".Set to @samp{yes} or @samp{no}.@end defvar@defvar dlopen_supportWhether @code{dlopen} is supported on the platform.Set to @samp{yes} or @samp{no}.@end defvar@defvar dlopen_selfWhether it is possible to @code{dlopen} the executable itself.Set to @samp{yes} or @samp{no}.@end defvar@defvar dlopen_self_staticWhether it is possible to @code{dlopen} the executable itself, when itis linked statically (@samp{-all-static}). Set to @samp{yes} or@samp{no}.@end defvar@defvar echoAn @code{echo} program which does not interpret backslashes as anescape character.@end defvar@defvar exclude_expsymsList of symbols that should not be listed in the preloaded symbols.@end defvar@defvar export_dynamic_flag_specCompiler link flag that allows a dlopened shared library to referencesymbols that are defined in the program.@end defvar@defvar export_symbols_cmdsCommands to extract exported symbols from @var{libobjs} to thefile @var{export_symbols}.@end defvar@defvar extract_expsyms_cmdsCommands to extract the exported symbols list from a shared library.These commands are executed if there is no file @var{$objdir/$soname-def},and should write the names of the exported symbols to that file, forthe use of @samp{old_archive_from_expsyms_cmds}.@end defvar@defvar fast_installDetermines whether libtool will privilege the installer or thedeveloper. The assumption is that installers will seldom run programsin the build tree, and the developer will seldom install. This is onlymeaningful on platforms in which @var{shlibpath_overrides_runpath} isnot @samp{yes}, so @var{fast_install} will be set to @samp{needless} inthis case. If @var{fast_install} set to @samp{yes}, libtool will createprograms that search for installed libraries, and, if a program is runin the build tree, a new copy will be linked on-demand to use theyet-to-be-installed libraries. If set to @samp{no}, libtool will createprograms that use the yet-to-be-installed libraries, and will linka new copy of the program at install time. The default value is@samp{yes} or @samp{needless}, depending on platform and configurationflags, and it can be turned from @samp{yes} to @samp{no} with theconfigure flag @samp{--disable-fast-install}.@end defvar@defvar finish_cmdsCommands to tell the dynamic linker how to find shared libraries in aspecific directory.@end defvar@defvar finish_evalSame as @var{finish_cmds}, except the commands are not displayed.@end defvar@defvar fix_srcfile_pathExpression to fix the shell variable $srcfile for the compiler.@end defvar@defvar global_symbol_pipeA pipeline that takes the output of @var{NM}, and produces a listing ofraw symbols followed by their C names. For example:@example$ @kbd{eval "$NM progname | $global_symbol_pipe"}D @var{symbol1} @var{C-symbol1}T @var{symbol2} @var{C-symbol2}C @var{symbol3} @var{C-symbol3}@dots{}$@end exampleThe first column contains the symbol type (used to tell data from codeon some platforms), but its meaning is system dependent.@end defvar@defvar global_symbol_to_cdeclA pipeline that translates the output of @var{global_symbol_pipe} intoproper C declarations. On platforms whose linkers differentiate codefrom data, such as HP/UX, data symbols will be declared as such, andcode symbols will be declared as functions. On platforms that don'tcare, everything is assumed to be data.@end defvar@defvar hardcode_actionEither @samp{immediate} or @samp{relink}, depending on whether sharedlibrary paths can be hardcoded into executables before they are installed,or if they need to be relinked.@end defvar@defvar hardcode_directSet to @samp{yes} or @samp{no}, depending on whether the linkerhardcodes directories if a library is directly specified on the commandline (such as @samp{@var{dir}/lib@var{name}.a}) when@var{hardcode_libdir_flag_spec} is specified.@end defvar@defvar hardcode_into_libsWhether the platform supports hardcoding of run-paths into libraries.If enabled, linking of programs will be much simpler but libraries willneed to be relinked during installation. Set to @samp{yes} or @samp{no}.@end defvar@defvar hardcode_libdir_flag_specFlag to hardcode a @var{libdir} variable into a binary, so that thedynamic linker searches @var{libdir} for shared libraries at runtime.If it is empty, libtool will try to use some other hardcoding mechanism.@end defvar@defvar hardcode_libdir_separatorIf the compiler only accepts a single @var{hardcode_libdir_flag}, thenthis variable contains the string that should separate multiplearguments to that flag.@end defvar@defvar hardcode_minus_LSet to @samp{yes} or @samp{no}, depending on whether the linkerhardcodes directories specified by @samp{-L} flags into the resultingexecutable when @var{hardcode_libdir_flag_spec} is specified.@end defvar@defvar hardcode_shlibpath_varSet to @samp{yes} or @samp{no}, depending on whether the linkerhardcodes directories by writing the contents of @samp{$shlibpath_var}into the resulting executable when @var{hardcode_libdir_flag_spec} isspecified. Set to @samp{unsupported} if directories specified by@samp{$shlibpath_var} are searched at run time, but not at link time.@end defvar@defvar host@defvarx host_aliasFor information purposes, set to the specified and canonical names ofthe system that libtool was configured for.@end defvar@defvar include_expsymsList of symbols that must always be exported when using @var{export_symbols}.@end defvar@defvar libextThe standard old archive suffix (normally "a").@end defvar@defvar libname_specThe format of a library name prefix. On all Unix systems, staticlibraries are called @samp{lib@var{name}.a}, but on some systems (suchas OS/2 or MS-DOS), the library is just called @samp{@var{name}.a}.@end defvar@defvar library_names_specA list of shared library names. The first is the name of the file,the rest are symbolic links to the file. The name in the list isthe file name that the linker finds when given @samp{-l@var{name}}.@end defvar@defvar link_all_deplibsWhether libtool must link a program against all its dependency libraries.Set to @samp{yes} or @samp{no}. Default is @samp{unknown}, which isa synonym for @samp{yes}.@end defvar@defvar link_static_flagLinker flag (passed through the C compiler) used to prevent dynamiclinking.@end defvar@defvar need_lib_prefixWhether libtool should automatically prefix module names with 'lib'.Set to @samp{yes} or @samp{no}. By default, it is @samp{unknown}, whichmeans the same as @samp{yes}, but documents that we are not really sureabout it.@samp{yes} means that it is possible both to @code{dlopen} and tolink against a library without 'lib' prefix,i.e. it requires @var{hardcode_direct} to be @samp{yes}.@end defvar@defvar need_versionWhether versioning is required for libraries, i.e. whether thedynamic linker requires a version suffix for all libraries.Set to @samp{yes} or @samp{no}. By default, it is @samp{unknown}, whichmeans the same as @samp{yes}, but documents that we are not really sureabout it.@end defvar@defvar need_locksWhether files must be locked to prevent conflicts when compilingsimultaneously. Set to @samp{yes} or @samp{no}.@end defvar@defvar no_builtin_flagCompiler flag to disable builtin functions that conflict with declaringexternal global symbols as @code{char}.@end defvar@defvar no_undefined_flagThe flag that is used by @samp{archive_cmds} in order to declare thatthere will be no unresolved symbols in the resulting shared library.Empty, if no such flag is required.@end defvar@defvar objdirThe name of the directory that contains temporary libtool files.@end defvar@defvar objextThe standard object file suffix (normally "o").@end defvar@defvar pic_flagAny additional compiler flags for building library object files.@end defvar@defvar postinstall_cmds@defvarx old_postinstall_cmdsCommands run after installing a shared or static library, respectively.@end defvar@defvar postuninstall_cmds@defvarx old_postuninstall_cmdsCommands run after uninstalling a shared or static library, respectively.@end defvar@defvar reload_cmds@defvarx reload_flagCommands to create a reloadable object.@end defvar@defvar runpath_varThe environment variable that tells the linker which directories tohardcode in the resulting executable.@end defvar@defvar shlibpath_overrides_runpathIndicates whether it is possible to override the hard-coded librarysearch path of a program with an environment variable. If this is setto no, libtool may have to create two copies of a program in the buildtree, one to be installed and one to be run in the build tree only.When each of these copies is created depends on the value of@code{fast_install}. The default value is @samp{unknown}, which isequivalent to @samp{no}.@end defvar@defvar shlibpath_varThe environment variable that tells the dynamic linker where to findshared libraries.@end defvar@defvar soname_specThe name coded into shared libraries, if different from the real name ofthe file.@end defvar@defvar striplib@defvarx old_striplibCommand to strip a shared (@code{striplib}) or static (@code{old_striplib})library, respectively. If these variables are empty, the strip flagin the install mode will be ignored for libraries (@pxref{Install mode}).@end defvar@defvar sys_lib_dlsearch_path_specExpression to get the run-time system library search path. Directoriesthat appear in this list are never hard-coded into executables.@end defvar@defvar sys_lib_search_path_specExpression to get the compile-time system library search path. Thisvariable is used by libtool when it has to test whether a certainlibrary is shared or static. The directories listed in@var{shlibpath_var} are automatically appended to this list, every timelibtool runs (i.e., not at configuration time), because some linkers usethis variable to extend the library search path. Linker switches suchas @code{-L} also augment the search path.@end defvar@defvar thread_safe_flag_specLinker flag (passed through the C compiler) used to generate thread-safelibraries.@end defvar@defvar version_typeThe library version numbering type. One of @samp{libtool},@samp{freebsd-aout}, @samp{freebsd-elf}, @samp{irix}, @samp{linux},@samp{osf}, @samp{sunos}, @samp{windows}, or @samp{none}.@end defvar@defvar whole_archive_flag_specCompiler flag to generate shared objects from convenience archives.@end defvar@defvar wlThe C compiler flag that allows libtool to pass a flag directly to thelinker. Used as: @code{$@{wl@}@var{some-flag}}.@end defvarVariables ending in @samp{_cmds} or @samp{_eval} contain a@samp{~}-separated list of commands that are @code{eval}ed one afteranother. If any of the commands return a nonzero exit status, libtoolgenerally exits with an error message.Variables ending in @samp{_spec} are @code{eval}ed before being used bylibtool.@node Cheap tricks@section Cheap tricksHere are a few tricks that you can use in order to make maintainershipeasier:@itemize @bullet@itemWhen people report bugs, ask them to use the @samp{--config},@samp{--debug}, or @samp{--features} flags, if you think they will helpyou. These flags are there to help you get information directly, ratherthan having to trust second-hand observation.@itemRather than reconfiguring libtool every time I make a change to@code{ltmain.in}, I keep a permanent @code{libtool} script in my@var{PATH}, which sources @code{ltmain.in} directly.The following steps describe how to create such a script, where@code{/home/src/libtool} is the directory containing the libtool sourcetree, @code{/home/src/libtool/libtool} is a libtool script that has beenconfigured for your platform, and @code{~/bin} is a directory in your@var{PATH}:@exampletrick$ cd ~/bintrick$ sed '/^# ltmain\.sh/q' /home/src/libtool/libtool > libtooltrick$ echo '. /home/src/libtool/ltmain.in' >> libtooltrick$ chmod +x libtooltrick$ libtool --versionltmain.sh (GNU @@PACKAGE@@) @@VERSION@@@@TIMESTAMP@@trick$@end example@end itemizeThe output of the final @samp{libtool --version} command shows that the@code{ltmain.in} script is being used directly. Now, modify@code{~/bin/libtool} or @code{/home/src/libtool/ltmain.in} directly inorder to test new changes without having to rerun @code{configure}.@include fdl.texi@page@node Index@unnumbered Index@printindex cp@c summarycontents@contents@bye