libtool: removed stale intro in document
[libtool.git] / doc / libtool.texi
blob84f565e54d6610f8ddcf60d9d1a8f6f6e745d806
1 \input texinfo   @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename libtool.info
4 @settitle Libtool
5 @c For double-sided printing, uncomment:
6 @c @setchapternewpage odd
7 @c Put everything in one index (arbitrarily chosen to be the concept index).
9 @syncodeindex vr cp
10 @syncodeindex fn cp
11 @syncodeindex tp cp
12 @synindex pg cp
13 @c %**end of header
15 @include version.texi
16 @set BUGADDR the Libtool bug reporting address @email{bug-libtool@@gnu.org}
17 @set MAILLIST the Libtool mailing list @email{libtool@@gnu.org}
18 @set objdir .libs
20 @copying
21 This manual is for GNU Libtool (version @value{VERSION}, @value{UPDATED}).
23 Copyright @copyright{} 1996--2019, 2021--2024 Free Software Foundation,
24 Inc.
26 Permission is granted to copy, distribute and/or modify this document
27 under the terms of the GNU Free Documentation License, Version 1.3
28 or any later version published by the Free Software Foundation;
29 with no Invariant Sections, with no Front-Cover Texts,
30 and with no Back-Cover Texts.  A copy of the license is included in
31 the section entitled ``GNU Free Documentation License''.
32 @end copying
34 @dircategory Software development
35 @direntry
36 * Libtool: (libtool).           Generic shared library support script.
37 @end direntry
39 @dircategory Individual utilities
40 @direntry
41 * libtool-invocation: (libtool)Invoking libtool. Running the @code{libtool} script.
42 * libtoolize: (libtool)Invoking libtoolize.      Adding libtool support.
43 @end direntry
45 @titlepage
46 @title GNU Libtool
47 @subtitle For version @value{VERSION}, @value{UPDATED}
48 @author Gordon Matzigkeit
49 @author Alexandre Oliva
50 @author Thomas Tanner
51 @author Gary V. Vaughan
53 @page
54 @vskip 0pt plus 1filll
55 @insertcopying
56 @end titlepage
58 @contents
60 @ifnottex
61 @node Top, Introduction, (dir), (dir)
62 @comment  node-name,  next,  previous,  up
63 @top Shared library support for GNU
65 This file documents GNU Libtool, a script that allows package developers
66 to provide generic shared library support.  This edition documents
67 version @value{VERSION}.
69 @xref{Reporting bugs}, for information on how to report problems with
70 GNU Libtool.
72 @menu
73 * Introduction::                What the heck is libtool?
74 * Libtool paradigm::            How libtool's view of libraries is different.
75 * Using libtool::               Example of using libtool to build libraries.
76 * Invoking libtool::            Running the @code{libtool} script.
77 * Integrating libtool::         Using libtool in your own packages.
78 * Other languages::             Using libtool without a C compiler.
79 * Versioning::                  Using library interface versions.
80 * Library tips::                Tips for library interface design.
81 * Inter-library dependencies::  Libraries that depend on other libraries.
82 * Dlopened modules::            @code{dlopen}ing libtool-created libraries.
83 * Using libltdl::               Libtool's portable @code{dlopen} wrapper library.
84 * Trace interface::             Libtool's trace interface.
85 * FAQ::                         Frequently Asked Questions
86 * Troubleshooting::             When libtool doesn't work as advertised.
87 * Maintaining::                 Information used by the libtool maintainer.
88 * GNU Free Documentation License::  License for this manual.
89 * Combined Index::              Full index.
91 @detailmenu
92  --- The Detailed Node Listing ---
94 Introduction
96 * Motivation::                  Why does GNU need a libtool?
97 * Issues::                      The problems that need to be addressed.
98 * Other implementations::       How other people have solved these issues.
99 * Postmortem::                  Learning from past difficulties.
101 Using libtool
103 * Creating object files::       Compiling object files for libraries.
104 * Linking libraries::           Creating libraries from object files.
105 * Linking executables::         Linking object files against libtool libraries.
106 * Debugging executables::       Running GDB on libtool-generated programs.
107 * Installing libraries::        Making libraries available to users.
108 * Installing executables::      Making programs available to users.
109 * Static libraries::            When shared libraries are not wanted.
111 Linking executables
113 * Wrapper executables::         Wrapper executables for some platforms.
115 Invoking @command{libtool}
117 * Compile mode::                Creating library object files.
118 * Link mode::                   Generating executables and libraries.
119 * Execute mode::                Debugging libtool-generated programs.
120 * Install mode::                Making libraries and executables public.
121 * Finish mode::                 Completing a library installation.
122 * Uninstall mode::              Removing installed executables and libraries.
123 * Clean mode::                  Removing uninstalled executables and libraries.
125 Integrating libtool with your package
127 * Autoconf macros::             Autoconf macros exported by libtool.
128 * Makefile rules::              Writing @file{Makefile} rules for libtool.
129 * Using Automake::              Automatically supporting libtool.
130 * Configuring::                 Configuring libtool for a host system.
131 * Distributing::                What files to distribute with your package.
132 * Static-only libraries::       Sometimes shared libraries are just a pain.
134 Configuring libtool
136 * LT_INIT::                     Configuring @code{libtool} in @file{configure.ac}.
137 * Configure notes::             Platform-specific notes for configuration.
139 Including libtool in your package
141 * Invoking libtoolize::         @code{libtoolize} command line options.
142 * Autoconf and LTLIBOBJS::      Autoconf automates LTLIBOBJS generation.
144 Using libtool with other languages
146 * C++ libraries::               Writing libraries for C++
147 * Tags::                        Tags
149 Library interface versions
151 * Interfaces::                  What are library interfaces?
152 * Libtool versioning::          Libtool's versioning system.
153 * Updating version info::       Changing version information before releases.
154 * Release numbers::             Breaking binary compatibility for aesthetics.
156 Tips for interface design
158 * C header files::              How to write portable include files.
160 Dlopened modules
162 * Building modules::            Creating dlopenable objects and libraries.
163 * Dlpreopening::                Dlopening that works on static platforms.
164 * Linking with dlopened modules::  Using dlopenable modules in libraries.
165 * Finding the dlname::          Choosing the right file to @code{dlopen}.
166 * Dlopen issues::               Unresolved problems that need your attention.
168 Using libltdl
170 * Libltdl interface::           How to use libltdl in your programs.
171 * Modules for libltdl::         Creating modules that can be @code{dlopen}ed.
172 * Thread Safety in libltdl::    Registering callbacks for multi-thread safety.
173 * User defined module data::    Associating data with loaded modules.
174 * Module loaders for libltdl::  Creating user defined module loaders.
175 * Distributing libltdl::        How to distribute libltdl with your package.
177 Frequently Asked Questions about libtool
179 * Stripped link flags::         Dropped flags when creating a library
181 Troubleshooting
183 * Libtool test suite::          Libtool's self-tests.
184 * Reporting bugs::              How to report problems with libtool.
186 The libtool test suite
188 * Test descriptions::           The contents of the old test suite.
189 * When tests fail::             What to do when a test fails.
191 Maintenance notes for libtool
193 * New ports::                   How to port libtool to new systems.
194 * Tested platforms::            When libtool was last tested.
195 * Platform quirks::             Information about different library systems.
196 * libtool script contents::     Configuration information that libtool uses.
197 * Cheap tricks::                Making libtool maintainership easier.
199 Porting libtool to new systems
201 * Information sources::         Where to find relevant documentation
202 * Porting inter-library dependencies::  Implementation details explained
204 Platform quirks
206 * References::                  Finding more information.
207 * Compilers::                   Creating object files from source files.
208 * Reloadable objects::          Binding object files together.
209 * Multiple dependencies::       Removing duplicate dependent libraries.
210 * Archivers::                   Programs that create static archives.
211 * Cross compiling::             Issues that arise when cross compiling.
212 * File name conversion::        Converting file names between platforms.
213 * Windows DLLs::                Windows header defines.
215 File name conversion
217 * File Name Conversion Failure::  What happens when file name conversion fails
218 * Native MinGW File Name Conversion::  MSYS file name conversion idiosyncrasies
219 * Cygwin/Windows File Name Conversion::  Using @command{cygpath} to convert Cygwin file names
220 * Unix/Windows File Name Conversion::  Using Wine to convert Unix paths
221 * LT_CYGPATH::                  Invoking @command{cygpath} from other environments
222 * Cygwin to MinGW Cross::       Other notes concerning MinGW cross
224 @end detailmenu
225 @end menu
227 @end ifnottex
229 @node Introduction
230 @chapter Introduction
232 In the past, if you were a source code package developer and wanted to
233 take advantage of the power of shared libraries, you needed to write
234 custom support code for each platform on which your package ran.  You
235 also had to design a configuration interface so that the package
236 installer could choose what sort of libraries were built.
238 GNU Libtool simplifies your job by encapsulating both the
239 platform-specific dependencies, and the user interface, in a single
240 script.  GNU Libtool is designed so that the complete functionality of
241 each host type is available via a generic interface, but nasty quirks
242 are hidden from the programmer.
244 GNU Libtool's consistent interface is reassuring@dots{} users don't need
245 to read obscure documentation to have their favorite source
246 package build shared libraries.  They just run your package
247 @code{configure} script (or equivalent), and libtool does all the dirty
248 work.
250 There are several examples throughout this document.  All assume the
251 same environment: we want to build a library, @file{libhello}, in a
252 generic way.
254 @file{libhello} could be a shared library, a static library, or
255 both@dots{} whatever is available on the host system, as long as libtool
256 has been ported to it.
258 This chapter explains the original design philosophy of libtool.  Feel
259 free to skip to the next chapter, unless you are interested in history,
260 or want to write code to extend libtool in a consistent way.
262 @menu
263 * Motivation::                  Why does GNU need a libtool?
264 * Issues::                      The problems that need to be addressed.
265 * Other implementations::       How other people have solved these issues.
266 * Postmortem::                  Learning from past difficulties.
267 @end menu
269 @node Motivation
270 @section Motivation for writing libtool
272 @cindex motivation for writing libtool
273 @cindex design philosophy
274 Since early 1995, several different GNU developers have recognized the
275 importance of having shared library support for their packages.  The
276 primary motivation for such a change is to encourage modularity and
277 reuse of code (both conceptually and physically) in GNU programs.
279 Such a demand means that the way libraries are built in GNU packages
280 needs to be general, to allow for any library type the package installer
281 might want.  The problem is compounded by the absence of a standard
282 procedure for creating shared libraries on different platforms.
284 The following sections outline the major issues facing shared library
285 support in GNU, and how shared library support could be standardized
286 with libtool.
288 @cindex specifications for libtool
289 @cindex libtool specifications
290 The following specifications were used in developing and evaluating this
291 system:
293 @enumerate
294 @item
295 The system must be as elegant as possible.
297 @item
298 The system must be fully integrated with the GNU Autoconf and Automake
299 utilities, so that it will be easy for GNU maintainers to use.  However,
300 the system must not require these tools, so that it can be used by
301 non-GNU packages.
303 @item
304 Portability to other (non-GNU) architectures and tools is desirable.
305 @end enumerate
307 @node Issues
308 @section Implementation issues
310 @cindex tricky design issues
311 @cindex design issues
312 The following issues need to be addressed in any reusable shared library
313 system, specifically libtool:
315 @enumerate
316 @item
317 The package installer should be able to control what sort of libraries
318 are built.
320 @item
321 It can be tricky to run dynamically linked programs whose libraries have
322 not yet been installed.  @code{LD_LIBRARY_PATH} must be set properly (if
323 it is supported), or programs fail to run.
325 @item
326 The system must operate consistently even on hosts that don't support
327 shared libraries.
329 @item
330 The commands required to build shared libraries may differ wildly from
331 host to host.  These need to be determined at configure time in
332 a consistent way.
334 @item
335 It is not always obvious with what prefix or suffix a shared library
336 should be installed.  This makes it difficult for @file{Makefile} rules,
337 since they generally assume that file names are the same from host to
338 host.
340 @item
341 The system needs a simple library version number abstraction, so that
342 shared libraries can be upgraded in place.  The programmer should be
343 informed how to design the interfaces to the library to maximize binary
344 compatibility.
346 @item
347 The install @file{Makefile} target should warn the package installer to set
348 the proper environment variables (@code{LD_LIBRARY_PATH} or equivalent),
349 or run @command{ldconfig}.
350 @end enumerate
352 @node Other implementations
353 @section Other implementations
355 Even before libtool was developed, many free software packages built and
356 installed their own shared libraries.  At first, these packages were
357 examined to avoid reinventing existing features.
359 Now it is clear that none of these packages have documented the details
360 of shared library systems that libtool requires.  So, other packages
361 have been more or less abandoned as influences.
363 @node Postmortem
364 @section A postmortem analysis of other implementations
366 @cindex other implementations, flaws in
367 @cindex reusability of library systems
368 In all fairness, each of the implementations that were examined do the
369 job that they were intended to do, for a number of different host
370 systems.  However, none of these solutions seem to function well as a
371 generalized, reusable component.
373 @cindex complexity of library systems
374 Most were too complex to use (much less modify) without understanding
375 exactly what the implementation does, and they were generally not
376 documented.
378 The main difficulty is that different vendors have different views of
379 what libraries are, and none of the packages that were examined seemed
380 to be confident enough to settle on a single paradigm that just
381 @emph{works}.
383 Ideally, libtool would be a standard that would be implemented as series
384 of extensions and modifications to existing library systems to make them
385 work consistently.  However, it is not an easy task to convince
386 operating system developers to mend their evil ways, and people want to
387 build shared libraries right now, even on buggy, broken, confused
388 operating systems.
390 For this reason, libtool was designed as an independent shell script.
391 It isolates the problems and inconsistencies in library building that
392 plague @file{Makefile} writers by wrapping the compiler suite on
393 different platforms with a consistent, powerful interface.
395 With luck, libtool will be useful to and used by the GNU community, and
396 that the lessons that were learned in writing it will be taken up by
397 designers of future library systems.
399 @node Libtool paradigm
400 @chapter The libtool paradigm
402 At first, libtool was designed to support an arbitrary number of library
403 object types.  After libtool was ported to more platforms, a new
404 paradigm gradually developed for describing the relationship between
405 libraries and programs.
407 @cindex definition of libraries
408 @cindex libraries, definition of
409 In summary, ``libraries are programs with multiple entry points, and
410 more formally defined interfaces.''
412 The best way to introduce the libtool paradigm is to contrast it with
413 the paradigm of existing library systems, with examples from each.  It
414 is a new way of thinking, so it may take a little time to absorb, but
415 when you understand it, the world becomes simpler.
417 @node Using libtool
418 @chapter Using libtool
420 @cindex examples of using libtool
421 @cindex libtool examples
422 It makes little sense to talk about using libtool in your own packages
423 until you have seen how it makes your life simpler.  The examples in
424 this chapter introduce the main features of libtool by comparing the
425 standard library building procedure to libtool's operation on two
426 different platforms:
428 @table @samp
429 @item a23
430 An Ultrix 4.2 platform with only static libraries.
432 @item burger
433 A NetBSD/i386 1.2 platform with shared libraries.
434 @end table
436 You can follow these examples on your own platform, using the
437 preconfigured libtool script that was installed with libtool
438 (@pxref{Configuring}).
440 Source files for the following examples are taken from the @file{demo}
441 subdirectory of the libtool distribution.  Assume that we are building a
442 library, @file{libhello}, out of the files @file{foo.c} and
443 @file{hello.c}.
445 Note that the @file{foo.c} source file uses the @code{cos} math library
446 function, which is usually found in the standalone math library, and not
447 the C library (@pxref{Trig Functions, , Trigonometric Functions, libc,
448 The GNU C Library Reference Manual}).  So, we need to add @option{-lm} to
449 the end of the link line whenever we link @file{foo.lo} into an
450 executable or a library (@pxref{Inter-library dependencies}).
452 The same rule applies whenever you use functions that don't appear in
453 the standard C library@dots{} you need to add the appropriate
454 @option{-l@var{name}} flag to the end of the link line when you link
455 against those objects.
457 After we have built that library, we want to create a program by linking
458 @file{main.o} against @file{libhello}.
460 @menu
461 * Creating object files::       Compiling object files for libraries.
462 * Linking libraries::           Creating libraries from object files.
463 * Linking executables::         Linking object files against libtool libraries.
464 * Debugging executables::       Running GDB on libtool-generated programs.
465 * Installing libraries::        Making libraries available to users.
466 * Installing executables::      Making programs available to users.
467 * Static libraries::            When shared libraries are not wanted.
468 @end menu
470 @node Creating object files
471 @section Creating object files
473 @cindex compiling object files
474 @cindex object files, compiling
475 To create an object file from a source file, the compiler is invoked
476 with the @option{-c} flag (and any other desired flags):
478 @example
479 burger$ @kbd{gcc -g -O -c main.c}
480 burger$
481 @end example
483 The above compiler command produces an object file, usually named
484 @file{main.o}, from the source file @file{main.c}.
486 For most library systems, creating object files that become part of a
487 static library is as simple as creating object files that are linked to
488 form an executable:
490 @example
491 burger$ @kbd{gcc -g -O -c foo.c}
492 burger$ @kbd{gcc -g -O -c hello.c}
493 burger$
494 @end example
496 @cindex position-independent code
497 @cindex PIC (position-independent code)
498 Shared libraries, however, may only be built from
499 @dfn{position-independent code} (PIC).  So, special flags must be passed
500 to the compiler to tell it to generate PIC rather than the standard
501 position-dependent code.
503 @cindex library object file
504 @cindex @file{.lo} files
505 @cindex object files, library
506 Since this is a library implementation detail, libtool hides the
507 complexity of PIC compiler flags and uses separate library object files
508 (the PIC one lives in the @file{@value{objdir}} subdirectory and the
509 static one lives in the current directory).  On systems without shared
510 libraries, the PIC library object files are not created, whereas on
511 systems where all code is PIC, such as AIX, the static ones are not
512 created.
514 To create library object files for @file{foo.c} and @file{hello.c},
515 simply invoke libtool with the standard compilation command as
516 arguments (@pxref{Compile mode}):
518 @example
519 a23$ @kbd{libtool --mode=compile gcc -g -O -c foo.c}
520 gcc -g -O -c foo.c -o foo.o
521 a23$ @kbd{libtool --mode=compile gcc -g -O -c hello.c}
522 gcc -g -O -c hello.c -o hello.o
523 a23$
524 @end example
526 Note that libtool silently creates an additional control file on each
527 @samp{compile} invocation.  The @file{.lo} file is the libtool object,
528 which Libtool uses to determine what object file may be built into a
529 shared library.  On @samp{a23}, only static libraries are supported so
530 the library objects look like this:
532 @example
533 # foo.lo - a libtool object file
534 # Generated by ltmain.sh (GNU libtool) @value{VERSION}
536 # Please DO NOT delete this file!
537 # It is necessary for linking the library.
539 # Name of the PIC object.
540 pic_object=none
542 # Name of the non-PIC object.
543 non_pic_object='foo.o'
544 @end example
546 On shared library systems, libtool automatically generates an
547 additional PIC object by inserting the appropriate PIC generation
548 flags into the compilation command:
550 @example
551 burger$ @kbd{libtool --mode=compile gcc -g -O -c foo.c}
552 mkdir @value{objdir}
553 gcc -g -O -c foo.c  -fPIC -DPIC -o @value{objdir}/foo.o
554 gcc -g -O -c foo.c -o foo.o >/dev/null 2>&1
555 burger$
556 @end example
558 Note that Libtool automatically created @file{@value{objdir}} directory
559 upon its first execution, where PIC library object files will be stored.
561 Since @samp{burger} supports shared libraries, and requires PIC
562 objects to build them, Libtool has compiled a PIC object this time,
563 and made a note of it in the libtool object:
565 @example
566 # foo.lo - a libtool object file
567 # Generated by ltmain.sh (GNU libtool) @value{VERSION}
569 # Please DO NOT delete this file!
570 # It is necessary for linking the library.
572 # Name of the PIC object.
573 pic_object='@value{objdir}/foo.o'
575 # Name of the non-PIC object.
576 non_pic_object='foo.o'
577 @end example
579 @cindex @option{-no-suppress}, libtool compile mode option
580 Notice that the second run of GCC has its output discarded.  This is
581 done so that compiler warnings aren't annoyingly duplicated.  If you
582 need to see both sets of warnings (you might have conditional code
583 inside @samp{#ifdef PIC} for example), you can turn off suppression with
584 the @option{-no-suppress} option to libtool's compile mode:
586 @example
587 burger$ @kbd{libtool --mode=compile gcc -no-suppress -g -O -c hello.c}
588 gcc -g -O -c hello.c  -fPIC -DPIC -o @value{objdir}/hello.o
589 gcc -g -O -c hello.c -o hello.o
590 burger$
591 @end example
594 @node Linking libraries
595 @section Linking libraries
597 @pindex ar
598 Without libtool, the programmer would invoke the @command{ar} command to
599 create a static library:
601 @example
602 burger$ @kbd{ar cr libhello.a hello.o foo.o}
603 burger$
604 @end example
606 @pindex ranlib
607 But of course, that would be too simple, so many systems require that
608 you run the @code{ranlib} command on the resulting library (to give it
609 better karma, or something):
611 @example
612 burger$ @kbd{ranlib libhello.a}
613 burger$
614 @end example
616 It seems more natural to use the C compiler for this task, given
617 libtool's ``libraries are programs'' approach.  So, on platforms without
618 shared libraries, libtool simply acts as a wrapper for the system
619 @command{ar} (and possibly @code{ranlib}) commands.
621 @cindex libtool libraries
622 @cindex @file{.la} files
623 Again, the libtool control file name (@file{.la} suffix) differs from
624 the standard library name (@file{.a} suffix).  The arguments to
625 libtool are the same ones you would use to produce an executable named
626 @file{libhello.la} with your compiler (@pxref{Link mode}):
628 @example
629 a23$ @kbd{libtool --mode=link gcc -g -O -o libhello.la foo.o hello.o}
630 *** Warning: Linking the shared library libhello.la against the
631 *** non-libtool objects foo.o hello.o is not portable!
632 ar cr .libs/libhello.a
633 ranlib .libs/libhello.a
634 creating libhello.la
635 (cd .libs && rm -f libhello.la && ln -s ../libhello.la libhello.la)
636 a23$
637 @end example
639 Aha!  Libtool caught a common error@dots{} trying to build a library
640 from standard objects instead of special @file{.lo} object files.  This
641 doesn't matter so much for static libraries, but on shared library
642 systems, it is of great importance.  (Note that you may replace
643 @file{libhello.la} with @file{libhello.a} in which case libtool won't
644 issue the warning any more.  But although this method works, this is
645 not intended to be used because it makes you lose the benefits of
646 using Libtool.)
648 So, let's try again, this time with the library object files.  Remember
649 also that we need to add @option{-lm} to the link command line because
650 @file{foo.c} uses the @code{cos} math library function (@pxref{Using
651 libtool}).
653 Another complication in building shared libraries is that we need to
654 specify the path to the directory wher they will (eventually) be
655 installed (in this case, @file{/usr/local/lib})@footnote{If you don't
656 specify an @code{rpath}, then libtool builds a libtool convenience
657 archive, not a shared library (@pxref{Static libraries}).}:
659 @example
660 a23$ @kbd{libtool --mode=link gcc -g -O -o libhello.la foo.lo hello.lo \
661                 -rpath /usr/local/lib -lm}
662 ar cr @value{objdir}/libhello.a foo.o hello.o
663 ranlib @value{objdir}/libhello.a
664 creating libhello.la
665 (cd @value{objdir} && rm -f libhello.la && ln -s ../libhello.la libhello.la)
666 a23$
667 @end example
669 Now, let's try the same trick on the shared library platform:
671 @example
672 burger$ @kbd{libtool --mode=link gcc -g -O -o libhello.la foo.lo hello.lo \
673                 -rpath /usr/local/lib -lm}
674 rm -fr  @value{objdir}/libhello.a @value{objdir}/libhello.la
675 ld -Bshareable -o @value{objdir}/libhello.so.0.0 @value{objdir}/foo.o @value{objdir}/hello.o -lm
676 ar cr @value{objdir}/libhello.a foo.o hello.o
677 ranlib @value{objdir}/libhello.a
678 creating libhello.la
679 (cd @value{objdir} && rm -f libhello.la && ln -s ../libhello.la libhello.la)
680 burger$
681 @end example
683 Now that's significantly cooler@dots{} Libtool just ran an obscure
684 @command{ld} command to create a shared library, as well as the static
685 library.
687 @cindex @file{@value{objdir}} subdirectory
688 Note how libtool creates extra files in the @file{@value{objdir}}
689 subdirectory, rather than the current directory.  This feature is to
690 make it easier to clean up the build directory, and to help ensure that
691 other programs fail horribly if you accidentally forget to use libtool
692 when you should.
694 Again, you may want to have a look at the @file{.la} file
695 to see what Libtool stores in it.  In particular, you will see that
696 Libtool uses this file to remember the destination directory for the
697 library (the argument to @option{-rpath}) as well as the dependency
698 on the math library (@samp{-lm}).
700 @node Linking executables
701 @section Linking executables
703 @cindex linking against installed libraries
704 If you choose at this point to @dfn{install} the library (put it in a
705 permanent location) before linking executables against it, then you
706 don't need to use libtool to do the linking.  Simply use the appropriate
707 @option{-L} and @option{-l} flags to specify the library's location.
709 @cindex buggy system linkers
710 Some system linkers insist on encoding the full directory name of each
711 shared library in the resulting executable.  Libtool has to work around
712 this misfeature by special magic to ensure that only permanent directory
713 names are put into installed executables.
715 @cindex security problems with buggy linkers
716 @cindex bugs, subtle ones caused by buggy linkers
717 The importance of this bug must not be overlooked: it won't cause
718 programs to crash in obvious ways.  It creates a security hole,
719 and possibly even worse, if you are modifying the library source code
720 after you have installed the package, you will change the behaviour of
721 the installed programs!
723 So, if you want to link programs against the library before you install
724 it, you must use libtool to do the linking.
726 @cindex linking against uninstalled libraries
727 Here's the old way of linking against an uninstalled library:
729 @example
730 burger$ @kbd{gcc -g -O -o hell.old main.o libhello.a -lm}
731 burger$
732 @end example
734 Libtool's way is almost the same@footnote{However, you should avoid using
735 @option{-L} or @option{-l} flags to link against an uninstalled libtool
736 library.  Just specify the relative path to the @file{.la} file, such as
737 @file{../intl/libintl.la}.  This is a design decision to eliminate any
738 ambiguity when linking against uninstalled shared libraries.}
739 (@pxref{Link mode}):
741 @example
742 a23$ @kbd{libtool --mode=link gcc -g -O -o hell main.o libhello.la}
743 gcc -g -O -o hell main.o  ./@value{objdir}/libhello.a -lm
744 a23$
745 @end example
747 That looks too simple to be true.  All libtool did was transform
748 @file{libhello.la} to @file{./@value{objdir}/libhello.a}, but remember
749 that @samp{a23} has no shared libraries.  Notice that Libtool also
750 remembered that @file{libhello.la} depends on @option{-lm}, so even
751 though we didn't specify @option{-lm} on the libtool command
752 line@footnote{
754 And why should we? @file{main.o} doesn't directly depend on @option{-lm}
755 after all.
757 } Libtool has added it to the @command{gcc} link line for us.
759 On @samp{burger} Libtool links against the uninstalled shared library:
761 @example
762 burger$ @kbd{libtool --mode=link gcc -g -O -o hell main.o libhello.la}
763 gcc -g -O -o @value{objdir}/hell main.o -L./@value{objdir} -R/usr/local/lib -lhello -lm
764 creating hell
765 burger$
766 @end example
768 @cindex linking with installed libtool libraries
769 Now assume @file{libhello.la} had already been installed, and you want
770 to link a new program with it.  You could figure out where it lives by
771 yourself, then run:
773 @example
774 burger$ @kbd{gcc -g -O -o test test.o -L/usr/local/lib -lhello -lm}
775 @end example
777 However, unless @file{/usr/local/lib} is in the standard library search
778 path, you won't be able to run @code{test}.  However, if you use libtool
779 to link the already-installed libtool library, it will do The Right
780 Thing (TM) for you:
782 @example
783 burger$ @kbd{libtool --mode=link gcc -g -O -o test test.o \
784                 /usr/local/lib/libhello.la}
785 gcc -g -O -o @value{objdir}/test test.o -Wl,--rpath \
786         -Wl,/usr/local/lib /usr/local/lib/libhello.a -lm
787 creating test
788 burger$
789 @end example
791 Note that libtool added the necessary run-time path flag, as well as
792 @option{-lm}, the library libhello.la depended upon.  Nice, huh?
794 @cindex wrapper scripts for programs
795 @cindex program wrapper scripts
796 Notice that the executable, @code{hell}, was actually created in the
797 @file{@value{objdir}} subdirectory.  Then, a wrapper script (or, on
798 certain platforms, a wrapper executable @pxref{Wrapper executables}) was
799 created in the current directory.
801 Since libtool created a wrapper script, you should use libtool to
802 install it and debug it too.  However, since the program does not depend
803 on any uninstalled libtool library, it is probably usable even without
804 the wrapper script.
806 On NetBSD 1.2, libtool encodes the installation directory of
807 @file{libhello}, by using the @samp{-R/usr/local/lib} compiler flag.
808 Then, the wrapper script guarantees that the executable finds the
809 correct shared library (the one in @file{./@value{objdir}}) until it is
810 properly installed.
812 Let's compare the two different programs:
814 @example
815 burger$ @kbd{time ./hell.old}
816 Welcome to GNU Hell!
817 ** This is not GNU Hello.  There is no built-in mail reader. **
818         0.21 real         0.02 user         0.08 sys
819 burger$ @kbd{time ./hell}
820 Welcome to GNU Hell!
821 ** This is not GNU Hello.  There is no built-in mail reader. **
822         0.63 real         0.09 user         0.59 sys
823 burger$
824 @end example
826 The wrapper script takes significantly longer to execute, but at least
827 the results are correct, even though the shared library hasn't been
828 installed yet.
830 So, what about all the space savings that shared libraries are supposed
831 to yield?
833 @example
834 burger$ @kbd{ls -l hell.old libhello.a}
835 -rwxr-xr-x  1 gord  gord  15481 Nov 14 12:11 hell.old
836 -rw-r--r--  1 gord  gord   4274 Nov 13 18:02 libhello.a
837 burger$ @kbd{ls -l @value{objdir}/hell @value{objdir}/libhello.*}
838 -rwxr-xr-x  1 gord  gord  11647 Nov 14 12:10 @value{objdir}/hell
839 -rw-r--r--  1 gord  gord   4274 Nov 13 18:44 @value{objdir}/libhello.a
840 -rwxr-xr-x  1 gord  gord  12205 Nov 13 18:44 @value{objdir}/libhello.so.0.0
841 burger$
842 @end example
844 Well, that sucks.  Maybe I should just scrap this project and take up
845 basket weaving.
847 Actually, it just proves an important point: shared libraries incur
848 overhead because of their (relative) complexity.  In this situation, the
849 price of being dynamic is eight kilobytes, and the payoff is about four
850 kilobytes.  So, having a shared @file{libhello} won't be an advantage
851 until we link it against at least a few more programs.
853 @menu
854 * Wrapper executables::         Wrapper executables for some platforms.
855 @end menu
857 @node Wrapper executables
858 @subsection Wrapper executables for uninstalled programs
859 @cindex wrapper executables for uninstalled programs
860 @cindex program wrapper executables
862 Some platforms, notably those hosted on Windows such as Cygwin
863 and MinGW, use a wrapper executable rather than a wrapper script
864 to ensure proper operation of uninstalled programs linked by libtool
865 against uninstalled shared libraries. The wrapper executable thus
866 performs the same function as the wrapper script used on other
867 platforms, but allows to satisfy the @command{make} rules for the
868 program, whose name ends in @code{$(EXEEXT)}. The actual program
869 executable is created below @value{objdir}, and its name will end
870 in @code{$(EXEEXT)} and may or may not contain an @code{lt-} prefix.
871 This wrapper executable sets various environment values so that the
872 program executable may locate its (uninstalled) shared libraries,
873 and then launches the program executable.
875 The wrapper executable provides a debug mode, enabled by passing the
876 command-line option @code{--lt-debug} (see below). When executing in
877 debug mode, diagnostic information will be printed to @code{stderr}
878 before the program executable is launched.
880 Finally, the wrapper executable supports a number of command line
881 options that may be useful when debugging the operation of the wrapper
882 system. All of these options begin with @code{--lt-}, and if present
883 they and their arguments will be removed from the argument list passed
884 on to the program executable.  Therefore, the program executable may not
885 employ command line options that begin with @code{--lt-}. (In fact, the
886 wrapper executable will detect any command line options that begin with
887 @code{--lt-} and abort with an error message if the option is not
888 recognized). If this presents a problem, please contact the Libtool
889 team at @value{BUGADDR}.
891 These command line options include:
893 @table @option
894 @item --lt-dump-script
895 Causes the wrapper to print a copy of the wrapper @emph{script}
896 to @code{stdout}, and exit.
898 @item --lt-debug
899 Causes the wrapper to print diagnostic information to @code{stdout},
900 before launching the program executable.
902 @end table
904 For consistency, both the wrapper @emph{script} and the wrapper
905 @emph{executable} support these options.
907 @node Debugging executables
908 @section Debugging executables
910 If @file{hell} was a complicated program, you would certainly want to
911 test and debug it before installing it on your system.  In the above
912 section, you saw how the libtool wrapper script makes it possible to run
913 the program directly, but unfortunately, this mechanism interferes with
914 the debugger:
916 @example
917 burger$ @kbd{gdb hell}
918 GDB is free software and you are welcome to distribute copies of it
919  under certain conditions; type "show copying" to see the conditions.
920 There is no warranty for GDB; type "show warranty" for details.
921 GDB 4.16 (i386-unknown-netbsd), (C) 1996 Free Software Foundation, Inc.
923 "hell": not in executable format: File format not recognized
925 (gdb) @kbd{quit}
926 burger$
927 @end example
929 Sad.  It doesn't work because GDB doesn't know where the executable
930 lives.  So, let's try again, by invoking GDB directly on the executable:
932 @example
933 burger$ @kbd{gdb @value{objdir}/hell}
934 GNU gdb 5.3 (i386-unknown-netbsd)
935 Copyright 2002 Free Software Foundation, Inc.
936 GDB is free software, covered by the GNU General Public License,
937 and you are welcome to change it and/or distribute copies of it
938 under certain conditions.  Type "show copying" to see the conditions.
939 There is no warranty for GDB.  Type "show warranty" for details.
940 (gdb) @kbd{break main}
941 Breakpoint 1 at 0x8048547: file main.c, line 29.
942 (gdb) @kbd{run}
943 Starting program: /home/src/libtool/demo/.libs/hell
944 /home/src/libtool/demo/.libs/hell: can't load library 'libhello.so.0'
946 Program exited with code 020.
947 (gdb) @kbd{quit}
948 burger$
949 @end example
951 Argh.  Now GDB complains because it cannot find the shared library that
952 @file{hell} is linked against.  So, we must use libtool to
953 properly set the library path and run the debugger.  Fortunately, we can
954 forget all about the @file{@value{objdir}} directory, and just run it on
955 the executable wrapper (@pxref{Execute mode}):
957 @example
958 burger$ @kbd{libtool --mode=execute gdb hell}
959 GNU gdb 5.3 (i386-unknown-netbsd)
960 Copyright 2002 Free Software Foundation, Inc.
961 GDB is free software, covered by the GNU General Public License,
962 and you are welcome to change it and/or distribute copies of it
963 under certain conditions.  Type "show copying" to see the conditions.
964 There is no warranty for GDB.  Type "show warranty" for details.
965 (gdb) @kbd{break main}
966 Breakpoint 1 at 0x8048547: file main.c, line 29.
967 (gdb) @kbd{run}
968 Starting program: /home/src/libtool/demo/.libs/hell
970 Breakpoint 1, main (argc=1, argv=0xbffffc40) at main.c:29
971 29        printf ("Welcome to GNU Hell!\n");
972 (gdb) @kbd{quit}
973 The program is running.  Quit anyway (and kill it)? (y or n) @kbd{y}
974 burger$
975 @end example
977 @node Installing libraries
978 @section Installing libraries
980 @pindex strip
981 Installing libraries on a non-libtool system is quite
982 straightforward@dots{} just copy them into place:@footnote{Don't
983 strip static libraries though, or they will be unusable.}
985 @pindex su
986 @example
987 burger$ @kbd{su}
988 Password: @kbd{********}
989 burger# @kbd{cp libhello.a /usr/local/lib/libhello.a}
990 burger#
991 @end example
993 Oops, don't forget the @command{ranlib} command:
995 @example
996 burger# @kbd{ranlib /usr/local/lib/libhello.a}
997 burger#
998 @end example
1000 @pindex install
1001 Libtool installation is quite simple, as well.  Just use the
1002 @command{install} or @command{cp} command that you normally would
1003 (@pxref{Install mode}):
1005 @example
1006 a23# @kbd{libtool --mode=install cp libhello.la /usr/local/lib/libhello.la}
1007 cp libhello.la /usr/local/lib/libhello.la
1008 cp @value{objdir}/libhello.a /usr/local/lib/libhello.a
1009 ranlib /usr/local/lib/libhello.a
1010 a23#
1011 @end example
1013 Note that the libtool library @file{libhello.la} is also installed, to
1014 help libtool with uninstallation (@pxref{Uninstall mode}) and linking
1015 (@pxref{Linking executables}) and to help programs with dlopening
1016 (@pxref{Dlopened modules}).
1018 Here is the shared library example:
1020 @example
1021 burger# @kbd{libtool --mode=install install -c libhello.la \
1022                 /usr/local/lib/libhello.la}
1023 install -c @value{objdir}/libhello.so.0.0 /usr/local/lib/libhello.so.0.0
1024 install -c libhello.la /usr/local/lib/libhello.la
1025 install -c @value{objdir}/libhello.a /usr/local/lib/libhello.a
1026 ranlib /usr/local/lib/libhello.a
1027 burger#
1028 @end example
1030 @cindex stripping libraries
1031 @cindex libraries, stripping
1032 It is safe to specify the @option{-s} (strip symbols) flag if you use a
1033 BSD-compatible install program when installing libraries.
1034 Libtool will either ignore the @option{-s} flag, or will run a program
1035 that will strip only debugging and compiler symbols from the library.
1037 Once the libraries have been put in place, there may be some additional
1038 configuration that you need to do before using them.  First, you must
1039 make sure that where the library is installed actually agrees with the
1040 @option{-rpath} flag you used to build it.
1042 @cindex postinstallation
1043 @cindex installation, finishing
1044 @cindex libraries, finishing installation
1045 Then, running @samp{libtool -n finish @var{libdir}} can give you
1046 further hints on what to do (@pxref{Finish mode}):
1048 @example
1049 burger# @kbd{libtool -n finish /usr/local/lib}
1050 PATH="$PATH:/sbin" ldconfig -m /usr/local/lib
1051 -----------------------------------------------------------------
1052 Libraries have been installed in:
1053    /usr/local/lib
1055 To link against installed libraries in a given directory, LIBDIR,
1056 you must use the '-LLIBDIR' flag during linking.
1058  You will also need to do one of the following:
1059    - add LIBDIR to the 'LD_LIBRARY_PATH' environment variable
1060      during execution
1061    - add LIBDIR to the 'LD_RUN_PATH' environment variable
1062      during linking
1063    - use the '-RLIBDIR' linker flag
1065 See any operating system documentation about shared libraries for
1066 more information, such as the ld and ld.so manual pages.
1067 -----------------------------------------------------------------
1068 burger#
1069 @end example
1071 After you have completed these steps, you can go on to begin using the
1072 installed libraries.  You may also install any executables that depend
1073 on libraries you created.
1075 @node Installing executables
1076 @section Installing executables
1078 If you used libtool to link any executables against uninstalled libtool
1079 libraries (@pxref{Linking executables}), you need to use libtool to
1080 install the executables after the libraries have been installed
1081 (@pxref{Installing libraries}).
1083 So, for our Ultrix example, we would run:
1085 @example
1086 a23# libtool --mode=install install -c hell /usr/local/bin/hell
1087 install -c hell /usr/local/bin/hell
1088 a23#
1089 @end example
1091 On shared library systems that require wrapper scripts, libtool just
1092 ignores the wrapper script and installs the correct binary:
1094 @example
1095 burger# libtool --mode=install install -c hell /usr/local/bin/hell
1096 install -c @value{objdir}/hell /usr/local/bin/hell
1097 burger#
1098 @end example
1101 @node Static libraries
1102 @section Linking static libraries
1104 @cindex static linking
1105 @cindex convenience libraries
1106 Why return to @command{ar} and @command{ranlib} silliness when you've had a
1107 taste of libtool?  Well, sometimes it is desirable to create a static
1108 archive that can never be shared.  The most frequent case is when you
1109 have a set of object files that you use to build several different
1110 libraries.  You can create a ``convenience library'' out of those
1111 objects, and link against that with the other libraries, instead of
1112 listing all the object files every time.
1114 If you just want to link this convenience library into programs, then
1115 you could just ignore libtool entirely, and use the old @command{ar} and
1116 @command{ranlib} commands (or the corresponding GNU Automake
1117 @samp{_LIBRARIES} rules).  You can even install a convenience library
1118 using GNU Libtool, though you probably don't want to and hence GNU
1119 Automake doesn't allow you to do so.
1121 @example
1122 burger$ @kbd{libtool --mode=install ./install-sh -c libhello.a \
1123                 /local/lib/libhello.a}
1124 ./install-sh -c libhello.a /local/lib/libhello.a
1125 ranlib /local/lib/libhello.a
1126 burger$
1127 @end example
1129 Using libtool for static library installation protects your library from
1130 being accidentally stripped (if the installer used the @option{-s} flag),
1131 as well as automatically running the correct @command{ranlib} command.
1133 But libtool libraries are more than just collections of object files:
1134 they can also carry library dependency information, which old archives
1135 do not.  If you want to create a libtool static convenience library, you
1136 can omit the @option{-rpath} flag and use @option{-static} to indicate that
1137 you're only interested in a static library.  When you link a program
1138 with such a library, libtool will actually link all object files and
1139 dependency libraries into the program.
1141 If you omit both @option{-rpath} and @option{-static}, libtool will create a
1142 convenience library that can be used to create other libtool
1143 libraries, even shared ones.  Just like in the static case, the library
1144 behaves as an alias to a set of object files and dependency libraries,
1145 but in this case the object files are suitable for inclusion in shared
1146 libraries.  But be careful not to link a single convenience library,
1147 directly or indirectly, into a single program or library, otherwise you
1148 may get errors about symbol redefinitions.
1150 The key is remembering that a convenience library contains PIC
1151 objects, and can be linked where a list of PIC objects makes sense;
1152 i.e.@: into a shared library.  A static convenience library contains
1153 non-PIC objects, so can be linked into an old static library, or
1154 a program.
1156 When GNU Automake is used, you should use @code{noinst_LTLIBRARIES}
1157 instead of @code{lib_LTLIBRARIES} for convenience libraries, so that
1158 the @option{-rpath} option is not passed when they are linked.
1160 As a rule of thumb, link a libtool convenience library into at most one
1161 libtool library, and never into a program, and link libtool static
1162 convenience libraries only into programs, and only if you need to carry
1163 library dependency information to the user of the static convenience
1164 library.
1166 @cindex standalone binaries
1167 Another common situation where static linking is desirable is in
1168 creating a standalone binary.  Use libtool to do the linking and add the
1169 @option{-all-static} flag.
1171 @node Invoking libtool
1172 @chapter Invoking @command{libtool}
1173 @pindex libtool
1174 @cindex libtool command options
1175 @cindex options, libtool command
1176 @cindex command options, libtool
1178 The @command{libtool} program has the following synopsis:
1180 @example
1181 libtool [@var{option}]@dots{} [@var{mode-arg}]@dots{}
1182 @end example
1184 @noindent
1185 and accepts the following options:
1187 @table @option
1188 @item --config
1189 Display libtool configuration variables and exit.
1191 @item --debug
1192 Dump a trace of shell script execution to standard output.  This
1193 produces a lot of output, so you may wish to pipe it to @command{less} (or
1194 @command{more}) or redirect to a file.
1196 @item -n
1197 @itemx --dry-run
1198 Don't create, modify, or delete any files, just show what commands would
1199 be executed by libtool.
1201 @item --features
1202 Display basic configuration options.  This provides a way for packages
1203 to determine whether shared or static libraries will be built.
1205 @item --finish
1206 Same as @option{--mode=finish}.
1208 @item -h
1209 Display short help message.
1211 @item --help
1212 Display a help message and exit.  If @option{--mode=@var{mode}} is
1213 specified, then detailed help for @var{mode} is displayed.
1215 @item --help-all
1216 Display help for the general options as well as detailed help for each
1217 operation mode, and exit.
1219 @item --mode=@var{mode}
1220 Use @var{mode} as the operation mode.  When using libtool from the
1221 command line, you can give just @var{mode} (or a unique abbreviation
1222 of it) as the first argument as a shorthand for the full
1223 @option{--mode=@var{mode}}.  For example, the following are equivalent:
1225 @example
1226 $ @kbd{libtool --mode=execute --dry-run gdb prog.exe}
1227 $ @kbd{libtool        execute --dry-run gdb prog.exe}
1228 $ @kbd{libtool        exe     --dry-run gdb prog.exe}
1229 $ @kbd{libtool        e       --dry-run gdb prog.exe}
1230 @end example
1232 @noindent
1233 @var{mode} must be set to one of the following:
1235 @table @option
1236 @item compile
1237 Compile a source file into a libtool object.
1239 @item execute
1240 Automatically set the library path so that another program can use
1241 uninstalled libtool-generated programs or libraries.
1243 @item link
1244 Create a library or an executable.
1246 @item install
1247 Install libraries or executables.
1249 @item finish
1250 Complete the installation of libtool libraries on the system.
1252 @item uninstall
1253 Delete installed libraries or executables.
1255 @item clean
1256 Delete uninstalled libraries or executables.
1257 @end table
1259 @item --tag=@var{tag}
1260 Use configuration variables from tag @var{tag} (@pxref{Tags}).
1262 @item --preserve-dup-deps
1263 Do not remove duplicate dependencies in libraries.  When building packages
1264 with static libraries, the libraries may depend circularly on each other
1265 (shared libs can too, but for those it doesn't matter), so there are
1266 situations, where -la -lb -la is required, and the second -la may not be
1267 stripped or the link will fail.  In cases where these duplications are
1268 required, this option will preserve them, only stripping the libraries
1269 that libtool knows it can safely.
1271 @item --quiet
1272 @itemx --silent
1273 Do not print out any progress or informational messages.
1275 @item -v
1276 @itemx --verbose
1277 Print out progress and informational messages (enabled by default),
1278 as well as additional messages not ordinary seen by default.
1280 @item --no-quiet
1281 @itemx --no-silent
1282 Print out the progress and informational messages that are seen
1283 by default. This option has no effect on whether the additional
1284 messages seen in @option{--verbose} mode are shown.
1286 @item --no-verbose
1287 Do not print out any additional informational messages beyond
1288 those ordinarily seen by default. This option has no effect
1289 on whether the ordinary progress and informational messages
1290 enabled by @option{--no-quiet} are shown.
1292 Thus, there are now three different message levels (not counting
1293 @option{--debug}), depending on whether the normal messages and/or
1294 the additional verbose messages are displayed.  Note that there is
1295 no mechanism to display verbose messages, without also displaying
1296 normal messages.
1298 @table @strong
1299 @item default
1300 Normal messages are displayed, verbose messages are not displayed.
1301 In addition to being the default mode, it can be forcibly achieved
1302 by using both option @option{--no-verbose} and either option
1303 @option{--no-silent} or option @option{--no-quiet}.
1305 @item silent
1306 Neither normal messages nor verbose messages are displayed. This
1307 mode can be achieved using either option @option{--silent} or
1308 option @option{--quiet}.
1310 @item verbose
1311 Both normal messages and verbose messages are displayed. This mode
1312 can be achieved using either option @option{-v} or option
1313 @option{--verbose}.
1314 @end table
1316 @item --version
1317 Print libtool version information and exit.
1318 @end table
1320 The current @command{libtool} implementation is done with a shell script
1321 that needs to be invoked by the shell that @command{configure} chose for
1322 configuring @command{libtool} (@pxref{config.status Invocation, , The
1323 Autoconf Manual, autoconf, The Autoconf Manual}).  This shell is set in
1324 the she-bang (@samp{#!}) line of the @command{libtool} script.  Using a
1325 different shell may cause undefined behavior.
1327 The @var{mode-args} are a variable number of arguments, depending on the
1328 selected operation mode.  In general, each @var{mode-arg} is interpreted
1329 by programs libtool invokes, rather than libtool itself.
1331 @menu
1332 * Compile mode::                Creating library object files.
1333 * Link mode::                   Generating executables and libraries.
1334 * Execute mode::                Debugging libtool-generated programs.
1335 * Install mode::                Making libraries and executables public.
1336 * Finish mode::                 Completing a library installation.
1337 * Uninstall mode::              Removing installed executables and libraries.
1338 * Clean mode::                  Removing uninstalled executables and libraries.
1339 @end menu
1341 @node Compile mode
1342 @section Compile mode
1343 @cindex mode, compile
1344 @cindex compile mode
1346 For @dfn{compile} mode, @var{mode-args} is a compiler command to be used
1347 in creating a ``standard'' object file.  These arguments should begin with
1348 the name of the C compiler, and contain the @option{-c} compiler flag so
1349 that only an object file is created.
1351 Libtool determines the name of the output file by removing the directory
1352 component from the source file name, then substituting the source code
1353 suffix (e.g.@: @samp{.c} for C source code) with the library object suffix,
1354 @samp{.lo}.
1356 If shared libraries are being built, any necessary PIC generation flags
1357 are substituted into the compilation command.
1359 The following components of @var{mode-args} are treated specially:
1361 @table @option
1362 @item -o
1363 Note that the @option{-o} option is now fully supported.  It is emulated
1364 on the platforms that don't support it (by locking and moving the
1365 objects), so it is really easy to use libtool, just with minor
1366 modifications to your Makefiles.  Typing for example
1367 @example
1368 libtool --mode=compile gcc -c foo/x.c -o foo/x.lo
1369 @end example
1370 will do what you expect.
1372 Note, however, that, if the compiler does not support @option{-c} and
1373 @option{-o}, it is impossible to compile @file{foo/x.c} without
1374 overwriting an existing @file{./x.o}.  Therefore, if you do have a
1375 source file @file{./x.c}, make sure you introduce dependencies in your
1376 @file{Makefile} to make sure @file{./x.o} (or @file{./x.lo}) is
1377 re-created after any sub-directory's @file{x.lo}:
1379 @example
1380 x.o x.lo: foo/x.lo bar/x.lo
1381 @end example
1383 @noindent
1384 This will also ensure that make won't try to use a temporarily corrupted
1385 @file{x.o} to create a program or library.  It may cause needless
1386 recompilation on platforms that support @option{-c} and @option{-o}
1387 together, but it's the only way to make it safe for those that don't.
1389 @item -no-suppress
1390 If both PIC and non-PIC objects are being built, libtool will normally
1391 suppress the compiler output for the PIC object compilation to save
1392 showing very similar, if not identical duplicate output for each
1393 object.  If the @option{-no-suppress} option is given in compile mode,
1394 libtool will show the compiler output for both objects.
1396 @item -prefer-pic
1397 Libtool will try to build only PIC objects.
1399 @item -prefer-non-pic
1400 Libtool will try to build only non-PIC objects.
1402 @item -shared
1403 Even if Libtool was configured with @option{--enable-static}, the object
1404 file Libtool builds will not be suitable for static linking.  Libtool
1405 will signal an error if it was configured with @option{--disable-shared},
1406 or if the host does not support shared libraries.
1408 @item -static
1409 Even if libtool was configured with @option{--disable-static}, the
1410 object file Libtool builds @strong{will} be suitable for static
1411 linking.
1413 @item -Wc,@var{flag}
1414 @itemx -Xcompiler @var{flag}
1415 Pass a flag directly to the compiler.  With @code{-Wc,}, multiple flags
1416 may be separated by commas, whereas @code{-Xcompiler } passes through
1417 commas unchanged.
1418 @end table
1420 @node Link mode
1421 @section Link mode
1422 @cindex link mode
1423 @cindex mode, link
1425 @dfn{Link} mode links together object files (including library
1426 objects) to form another library or to create an executable program.
1428 @var{mode-args} consist of a command using the C compiler to create an
1429 output file (with the @option{-o} flag) from several object files.
1431 The following components of @var{mode-args} are treated specially:
1433 @table @option
1434 @cindex undefined symbols, allowing
1435 @cindex unresolved symbols, allowing
1436 @item -all-static
1437 If @var{output-file} is a program, then do not link it against any
1438 shared libraries at all.  If @var{output-file} is a library, then only
1439 create a static library.  In general, this flag cannot be used together
1440 with @samp{disable-static} (@pxref{LT_INIT}).
1442 @item -avoid-version
1443 Tries to avoid versioning (@pxref{Versioning}) for libraries and modules,
1444 i.e.@: no version information is stored and no symbolic links are created.
1445 If the platform requires versioning, this option has no effect.
1447 @item -bindir
1448 Pass the absolute name of the directory for installing executable
1449 programs (@pxref{Directory Variables, , Directory Variables, standards,
1450 The GNU Coding Standards}).  @command{libtool} may use this value to
1451 install shared libraries there on systems that do not provide for any
1452 library hardcoding and use the directory of a program and the @env{PATH}
1453 variable as library search path.  This is typically used for DLLs on
1454 Windows or other systems using the PE (Portable Executable) format.
1455 On other systems, @option{-bindir} is ignored.  The default value used
1456 is @file{@var{libdir}/../bin} for libraries installed to
1457 @file{@var{libdir}}.  You should not use @option{-bindir} for modules.
1459 @item -dlopen @var{file}
1460 Same as @option{-dlpreopen @var{file}}, if native dlopening is not
1461 supported on the host platform (@pxref{Dlopened modules}) or if
1462 the program is linked with @option{-static},
1463 @option{-static-libtool-libs}, or @option{-all-static}.  Otherwise, no
1464 effect.  If @var{file} is @code{self} Libtool will make sure that the
1465 program can @code{dlopen} itself, either by enabling
1466 @option{-export-dynamic} or by falling back to @option{-dlpreopen self}.
1468 @item -dlpreopen @var{file}
1469 Link @var{file} into the output program, and add its symbols to the
1470 list of preloaded symbols (@pxref{Dlpreopening}).  If @var{file} is
1471 @code{self}, the symbols of the program itself will be added to
1472 preloaded symbol lists.  If @var{file} is @code{force} Libtool will
1473 make sure that a preloaded symbol list is always @emph{defined},
1474 regardless of whether it's empty or not.
1476 @item -export-dynamic
1477 Allow symbols from @var{output-file} to be resolved with @code{dlsym}
1478 (@pxref{Dlopened modules}).
1480 @item -export-symbols @var{symfile}
1481 Tells the linker to export only the symbols listed in @var{symfile}.
1482 The symbol file should end in @file{.sym} and must contain the name of one
1483 symbol per line.  This option has no effect on some platforms.
1484 By default all symbols are exported.
1486 @item -export-symbols-regex @var{regex}
1487 Same as @option{-export-symbols}, except that only symbols matching
1488 the regular expression @var{regex} are exported.
1489 By default all symbols are exported.
1491 @item -L@var{libdir}
1492 Search @var{libdir} for required libraries that have already been
1493 installed.
1495 @item -l@var{name}
1496 @var{output-file} requires the installed library @file{lib@var{name}}.
1497 This option is required even when @var{output-file} is not an
1498 executable.
1500 @item -module
1501 Creates a library that can be dlopened (@pxref{Dlopened modules}).
1502 This option doesn't work for programs.
1503 Module names don't need to be prefixed with @samp{lib}.
1504 In order to prevent name clashes, however, @file{lib@var{name}} and @file{@var{name}}
1505 must not be used at the same time in your package.
1507 @item -no-fast-install
1508 Disable fast-install mode for the executable @var{output-file}.  Useful
1509 if the program won't be necessarily installed.
1511 @item -no-install
1512 Link an executable @var{output-file} that can't be installed and
1513 therefore doesn't need a wrapper script on systems that allow hardcoding
1514 of library paths.  Useful if the program is only used in the build tree,
1515 e.g., for testing or generating other files.
1517 @item -no-undefined
1518 Declare that @var{output-file} does not depend on any libraries other
1519 than the ones listed on the command line, i.e., after linking, it will
1520 not have unresolved symbols.  Some platforms require all symbols in
1521 shared libraries to be resolved at library creation (@pxref{Inter-library
1522 dependencies}), and using this parameter allows @command{libtool} to
1523 assume that this will not happen.
1525 @item -o @var{output-file}
1526 Create @var{output-file} from the specified objects and libraries.
1528 @item -objectlist @var{file}
1529 Use a list of object files found in @var{file} to specify objects.
1531 @item -os2dllname @var{name}
1532 Use this to change the DLL base name on OS/2 to @var{name}, to keep
1533 within the 8 character base name limit on this system.
1535 @item -precious-files-regex @var{regex}
1536 Prevents removal of files from the temporary output directory whose
1537 names match this regular expression.  You might specify @samp{\.bbg?$}
1538 to keep those files created with @code{gcc -ftest-coverage} for example.
1540 @item -release @var{release}
1541 Specify that the library was generated by release @var{release} of your
1542 package, so that users can easily tell what versions are newer than
1543 others.  Be warned that no two releases of your package will be binary
1544 compatible if you use this flag.  If you want binary compatibility, use
1545 the @option{-version-info} flag instead (@pxref{Versioning}).
1547 @item -rpath @var{libdir}
1548 If @var{output-file} is a library, it will eventually be installed in
1549 @var{libdir}.  If @var{output-file} is a program, add @var{libdir} to
1550 the run-time path of the program.  On platforms that don't support
1551 hardcoding library paths into executables and only search PATH for
1552 shared libraries, such as when @var{output-file} is a Windows (or
1553 other PE platform) DLL, the @file{.la} control file will be installed in
1554 @var{libdir}, but see @option{-bindir} above for the eventual destination
1555 of the @file{.dll} or other library file itself.
1557 @item -R @var{libdir}
1558 If @var{output-file} is a program, add @var{libdir} to its run-time
1559 path.  If @var{output-file} is a library, add @option{-R@var{libdir}} to its
1560 @var{dependency_libs}, so that, whenever the library is linked into a
1561 program, @var{libdir} will be added to its run-time path.
1563 @item -shared
1564 If @var{output-file} is a program, then link it against any
1565 uninstalled shared libtool libraries (this is the default behavior).
1566 If @var{output-file} is a library, then only create a shared library.
1567 In the later case, libtool will signal an error if it was configured
1568 with @option{--disable-shared}, or if the host does not support shared
1569 libraries.
1571 @item -shrext @var{suffix}
1572 If @var{output-file} is a libtool library, replace the system's standard
1573 file name extension for shared libraries with @var{suffix} (most systems
1574 use @file{.so} here).  This option is helpful in certain cases where an
1575 application requires that shared libraries (typically modules) have an
1576 extension other than the default one.  Please note you must supply the
1577 full file name extension including any leading dot.
1579 @item -static
1580 If @var{output-file} is a program, then do not link it against any
1581 uninstalled shared libtool libraries.  If @var{output-file} is a
1582 library, then only create a static library.
1584 @item -static-libtool-libs
1585 If @var{output-file} is a program, then do not link it against any
1586 shared libtool libraries.  If @var{output-file} is a library, then only
1587 create a static library.
1589 @item -version-info @var{current}[:@var{revision}[:@var{age}]]
1590 If @var{output-file} is a libtool library, use interface version
1591 information @var{current}, @var{revision}, and @var{age} to build it
1592 (@pxref{Versioning}).  Do @strong{not} use this flag to specify package
1593 release information, rather see the @option{-release} flag.
1595 @item -version-number @var{major}[:@var{minor}[:@var{revision}]]
1596 If @var{output-file} is a libtool library, compute interface version
1597 information so that the resulting library uses the specified major, minor and
1598 revision numbers.  This is designed to permit libtool to be used with
1599 existing projects where identical version numbers are already used across
1600 operating systems.  New projects should use the @option{-version-info} flag
1601 instead.
1603 @item -weak @var{libname}
1604 if @var{output-file} is a libtool library, declare that it provides a
1605 weak @var{libname} interface.  This is a hint to libtool that there is
1606 no need to append @var{libname} to the list of dependency libraries of
1607 @var{output-file}, because linking against @var{output-file} already
1608 supplies the same interface (@pxref{Linking with dlopened modules}).
1610 @item -Wc,@var{flag}
1611 @itemx -Xcompiler @var{flag}
1612 Pass a linker-specific flag directly to the compiler.  With @code{-Wc,},
1613 multiple flags may be separated by commas, whereas @code{-Xcompiler }
1614 passes through commas unchanged.
1616 @item -Wa,@var{flag}
1617 @itemx -Xassembler @var{flag}
1618 Pass a linker-specific flag directly to the assembler.  With @code{-Wa,},
1619 multiple flags may be separated by commas, whereas @code{-Xassembler }
1620 passes through commas unchanged.
1622 @item -Wl,@var{flag}
1623 @itemx -Xlinker @var{flag}
1624 Pass a linker-specific flag directly to the linker.
1626 @item -XCClinker @var{flag}
1627 Pass a link-specific flag to the compiler driver (@code{CC}) during linking.
1628 @end table
1630 If the @var{output-file} ends in @file{.la}, then a libtool library is
1631 created, which must be built only from library objects (@file{.lo} files).
1632 The @option{-rpath} option is required.  In the current implementation,
1633 libtool libraries may not depend on other uninstalled libtool libraries
1634 (@pxref{Inter-library dependencies}).
1636 If the @var{output-file} ends in @file{.a}, then a standard library is
1637 created using @code{ar} and possibly @code{ranlib}.
1639 @cindex partial linking
1640 @cindex linking, partial
1641 If @var{output-file} ends in @file{.o} or @file{.lo}, then a reloadable object
1642 file is created from the input files (generally using @samp{ld -r}).
1643 This method is often called @dfn{partial linking}.
1645 Otherwise, an executable program is created.
1647 @node Execute mode
1648 @section Execute mode
1649 @cindex execute mode
1650 @cindex mode, execute
1652 For @dfn{execute} mode, the library path is automatically set, then a
1653 program is executed.
1655 The first of the @var{mode-args} is treated as a program name, with the
1656 rest as arguments to that program.
1658 The following components of @var{mode-args} are treated specially:
1660 @table @option
1661 @item -dlopen @var{file}
1662 Add the directory containing @var{file} to the library path.
1663 @end table
1665 This mode sets the library path environment variable according to any
1666 @option{-dlopen} flags.
1668 If any of the @var{args} are libtool executable wrappers, then they are
1669 translated into the name of their corresponding uninstalled binary, and
1670 any of their required library directories are added to the library path.
1672 @node Install mode
1673 @section Install mode
1674 @cindex install mode
1675 @cindex mode, install
1677 In @dfn{install} mode, libtool interprets most of the elements of
1678 @var{mode-args} as an installation command beginning with
1679 @command{cp}, or a BSD-compatible @command{install} program.
1681 The following components of @var{mode-args} are treated specially:
1683 @table @option
1684 @item -inst-prefix-dir @var{inst-prefix-dir}
1685 When installing into a temporary staging area, rather than the
1686 final @code{prefix}, this argument is used to reflect the
1687 temporary path, in much the same way @command{automake} uses
1688 @env{DESTDIR}.  For instance, if @code{prefix} is @file{/usr/local},
1689 but @var{inst-prefix-dir} is @file{/tmp}, then the object will be
1690 installed under @file{/tmp/usr/local/}.  If the installed object
1691 is a libtool library, then the internal fields of that library
1692 will reflect only @code{prefix}, not @var{inst-prefix-dir}:
1694 @example
1695 # Directory that this library needs to be installed in:
1696 libdir='/usr/local/lib'
1697 @end example
1701 @example
1702 # Directory that this library needs to be installed in:
1703 libdir='/tmp/usr/local/lib'
1704 @end example
1706 @code{inst-prefix} is also used to ensure that if the installed
1707 object must be relinked upon installation, that it is relinked
1708 against the libraries in @var{inst-prefix-dir}/@code{prefix},
1709 not @code{prefix}.
1711 In truth, this option is not really intended for use when calling
1712 libtool directly; it is automatically used when @code{libtool --mode=install}
1713 calls @code{libtool --mode=relink}.  Libtool does this by
1714 analyzing the destination path given in the original
1715 @code{libtool --mode=install} command and comparing it to the
1716 expected installation path established during @code{libtool --mode=link}.
1718 Thus, end-users need change nothing, and @command{automake}-style
1719 @code{make install DESTDIR=/tmp} will Just Work(tm) most of the time.
1720 For systems where fast installation cannot be turned on, relinking
1721 may be needed.  In this case, a @samp{DESTDIR} install will fail.
1723 Currently it is not generally possible to install into a temporary
1724 staging area that contains needed third-party libraries that are
1725 not yet visible at their final location.
1726 @end table
1728 The rest of the @var{mode-args} are interpreted as arguments to the
1729 @command{cp} or @command{install} command.
1731 The command is run, and any necessary unprivileged post-installation
1732 commands are also completed.
1734 @node Finish mode
1735 @section Finish mode
1736 @cindex finish mode
1737 @cindex mode, finish
1739 @dfn{Finish} mode has two functions.  One is to help system administrators
1740 install libtool libraries so that they can be located and linked into
1741 user programs.  To invoke this functionality, pass the name of a library
1742 directory as @var{mode-arg}.  Running this command may require superuser
1743 privileges, and the @option{--dry-run} option may be useful.
1745 The second is to facilitate transferring libtool libraries to a native
1746 compilation environment after they were built in a cross-compilation
1747 environment.  Cross-compilation environments may rely on recent libtool
1748 features, and running libtool in finish mode will make it easier to
1749 work with older versions of libtool.  This task is performed whenever
1750 the @var{mode-arg} is a @file{.la} file.
1752 @node Uninstall mode
1753 @section Uninstall mode
1754 @cindex uninstall mode
1755 @cindex mode, uninstall
1757 @dfn{Uninstall} mode deletes installed libraries, executables and objects.
1759 The first @var{mode-arg} is the name of the program to use to delete
1760 files (typically @command{/bin/rm}).
1762 The remaining @var{mode-args} are either flags for the deletion program
1763 (beginning with a @samp{-}), or the names of files to delete.
1765 @node Clean mode
1766 @section Clean mode
1767 @cindex clean mode
1768 @cindex mode, clean
1770 @dfn{Clean} mode deletes uninstalled libraries, executables, objects
1771 and libtool's temporary files associated with them.
1773 The first @var{mode-arg} is the name of the program to use to delete
1774 files (typically @command{/bin/rm}).
1776 The remaining @var{mode-args} are either flags for the deletion program
1777 (beginning with a @samp{-}), or the names of files to delete.
1779 @node Integrating libtool
1780 @chapter Integrating libtool with your package
1782 This chapter describes how to integrate libtool with your packages so
1783 that your users can install hassle-free shared libraries.
1785 There are several ways that Libtool may be integrated in your
1786 package, described in the following sections.  Typically, the Libtool
1787 macro files as well as @file{ltmain.sh} are copied into your package
1788 using @command{libtoolize} and @command{aclocal} after setting up the
1789 @file{configure.ac} and toplevel @file{Makefile.am}, then
1790 @command{autoconf} adds the needed tests to the @file{configure} script.
1791 These individual steps are often automated with @command{autoreconf}.
1793 Here is a diagram showing how such a typical Libtool configuration works
1794 when preparing a package for distribution, assuming that @file{m4} has
1795 been chosen as location for additional Autoconf macros, and
1796 @file{build-aux} as location for auxiliary build tools (@pxref{Input,,
1797 The Autoconf Manual, autoconf, The Autoconf Manual}):
1799 @example
1800 @group
1801 libtool.m4 -----.                .--> aclocal.m4 -----.
1802 ltoptions.m4 ---+  .-> aclocal* -+                    +--> autoconf*
1803 ltversion.m4 ---+--+             `--> [copy in m4/] --+       |
1804 ltsugar.m4 -----+  |                    ^             |       \/
1805 lt~obsolete.m4 -+  +-> libtoolize* -----'             |    configure
1806 [ltdl.m4] ------+  |                                  |
1807                    `----------------------------------'
1809 ltmain.sh -----------> libtoolize* -> [copy in build-aux/]
1810 @end group
1811 @end example
1813 During configuration, the @file{libtool} script is generated either
1814 through @command{config.status} or @command{config.lt}:
1816 @example
1817 @group
1818              .--> config.status* --.
1819 configure* --+                     +--> libtool
1820              `--> [config.lt*] ----'      ^
1821                                           |
1822 ltmain.sh --------------------------------'
1823 @end group
1824 @end example
1826 At @command{make} run time, @command{libtool} is then invoked as needed
1827 as a wrapper around compilers, linkers, install and cleanup programs.
1829 There are alternatives choices to several parts of the setup; for
1830 example, the Libtool macro files can either be copied or symlinked into
1831 the package, or copied into @file{aclocal.m4}.  As another example, an
1832 external, pre-configured @command{libtool} script may be used,
1833 by-passing most of the tests and package-specific setup for Libtool.
1835 @menu
1836 * Autoconf macros::             Autoconf macros exported by libtool.
1837 * Makefile rules::              Writing @file{Makefile} rules for libtool.
1838 * Using Automake::              Automatically supporting libtool.
1839 * Configuring::                 Configuring libtool for a host system.
1840 * Distributing::                What files to distribute with your package.
1841 * Static-only libraries::       Sometimes shared libraries are just a pain.
1842 @end menu
1844 @node Autoconf macros
1845 @section Autoconf macros exported by libtool
1847 Libtool uses a number of macros to interrogate the host system when it
1848 is being built, and you can use some of them yourself too.  Although
1849 there are a great many other macros in the libtool installed m4 files,
1850 these do not form part of the published interface, and are subject to
1851 change between releases.
1853 @noindent
1854 Macros in the @samp{LT_CMD_} namespace check for various shell
1855 commands:
1857 @defmac LT_CMD_MAX_LEN
1858 Finds the longest command line that can be safely passed to
1859 @samp{$SHELL} without being truncated, and store in the shell variable
1860 @samp{$max_cmd_len}.  It is only an approximate value, but command
1861 lines of this length or shorter are guaranteed not to be truncated.
1862 @end defmac
1864 @noindent
1865 Macros in the @samp{LT_FUNC_} namespace check characteristics of
1866 library functions:
1868 @defmac LT_FUNC_DLSYM_USCORE
1869 @samp{AC_DEFINE} the preprocessor symbol @samp{DLSYM_USCORE} if we
1870 have to add an underscore to symbol-names passed in to @samp{dlsym}.
1871 @end defmac
1873 @noindent
1874 Macros in the @samp{LT_LIB_} namespace check characteristics of system
1875 libraries:
1877 @defmac LT_LIB_M
1878 Set @samp{LIBM} to the math library or libraries required on this
1879 machine, if any.
1880 @end defmac
1882 @defmac LT_LIB_DLLOAD
1883 This is the macro used by @samp{libltdl} to determine what dlloaders
1884 to use on this machine, if any.  Several shell variables are set (and
1885 @samp{AC_SUBST}ed) depending on the dlload interfaces are available on
1886 this machine.  @samp{LT_DLLOADERS} contains a list of libtool
1887 libraries that can be used, and if necessary also sets
1888 @samp{LIBADD_DLOPEN} if additional system libraries are required by
1889 the @samp{dlopen} loader, and @samp{LIBADD_SHL_LOAD} if additional
1890 system libraries are required by the @samp{shl_load} loader,
1891 respectively.  Finally some symbols are set in @file{config.h}
1892 depending on the loaders that are found to work: @samp{HAVE_LIBDL},
1893 @samp{HAVE_SHL_LOAD}, @samp{HAVE_DYLD}, @samp{HAVE_DLD}.
1894 @end defmac
1896 @noindent
1897 Macros in the @samp{LT_PATH_} namespace search the system for the full
1898 path to particular system commands:
1900 @defmac LT_PATH_LD
1901 Add a @option{--with-gnu-ld} option to @file{configure}.  Try to find
1902 the path to the linker used by @samp{$CC}, and whether it is the
1903 GNU linker.  The result is stored in the shell variable
1904 @samp{$LD}, which is @code{AC_SUBST}ed.
1905 @end defmac
1907 @defmac LT_PATH_NM
1908 Try to find a BSD-compatible @command{nm} or a MS-compatible
1909 @command{dumpbin} command on this machine.  The result is stored in the
1910 shell variable @samp{$NM}, which is @code{AC_SUBST}ed.
1911 @end defmac
1913 @noindent
1914 Macros in the @samp{LT_SYS_} namespace probe for system
1915 characteristics:
1917 @defmac LT_SYS_DLOPEN_SELF
1918 Tests whether a program can dlopen itself, and then also whether the
1919 same program can still dlopen itself when statically linked.  Results
1920 are stored in the shell variables @samp{$enable_dlopen_self} and
1921 @samp{enable_dlopen_self_static} respectively.
1922 @end defmac
1924 @defmac LT_SYS_DLOPEN_DEPLIBS
1925 Define the preprocessor symbol @samp{LTDL_DLOPEN_DEPLIBS} if the
1926 OS needs help to load dependent libraries for @samp{dlopen} (or
1927 equivalent).
1928 @end defmac
1930 @defmac LT_SYS_DLSEARCH_PATH
1931 Define the preprocessor symbol @samp{LT_DLSEARCH_PATH} to the system
1932 default library search path.
1933 @end defmac
1935 @defmac LT_SYS_MODULE_EXT
1936 Define the preprocessor symbol @samp{LT_MODULE_EXT} to the extension
1937 used for runtime loadable modules.  If you use libltdl to open
1938 modules, then you can simply use the libtool library extension,
1939 @file{.la}.
1940 @end defmac
1942 @defmac LT_SYS_MODULE_PATH
1943 Define the preprocessor symbol @samp{LT_MODULE_PATH_VAR} to the name
1944 of the shell environment variable that determines the run-time module
1945 search path.
1946 @end defmac
1948 @defmac LT_SYS_SYMBOL_USCORE
1949 Set the shell variable @samp{sys_symbol_underscore} to @samp{no}
1950 unless the compiler prefixes global symbols with an underscore.
1951 @end defmac
1954 @node Makefile rules
1955 @section Writing @file{Makefile} rules for libtool
1956 @cindex Makefile
1957 @cindex Makefile.am
1958 @cindex Makefile.in
1960 Libtool is fully integrated with Automake (@pxref{Top,, Introduction,
1961 automake, The Automake Manual}), starting with Automake version 1.2.
1963 If you want to use libtool in a regular @file{Makefile} (or
1964 @file{Makefile.in}), you are on your own.  If you're not using
1965 Automake, and you don't know how to incorporate libtool into your
1966 package you need to do one of the following:
1968 @enumerate 1
1969 @item
1970 Download the latest Automake distribution from your nearest GNU
1971 mirror, install it, and start using it.
1973 @item
1974 Learn how to write @file{Makefile} rules by hand.  They're sometimes complex,
1975 but if you're clever enough to write rules for compiling your old
1976 libraries, then you should be able to figure out new rules for libtool
1977 libraries (hint: examine the @file{Makefile.in} in the @file{tests/demo}
1978 subdirectory of the libtool distribution@dots{} note especially that it
1979 was automatically generated from the @file{Makefile.am} by Automake).
1980 @end enumerate
1982 @node Using Automake
1983 @section Using Automake with libtool
1985 @vindex LTLIBRARIES
1986 Libtool library support is implemented under the @samp{LTLIBRARIES}
1987 primary.
1989 Here are some samples from the Automake @file{Makefile.am} in the
1990 libtool distribution's @file{demo} subdirectory.
1992 First, to link a program against a libtool library, just use the
1993 @samp{program_LDADD}@footnote{@c
1995 Since GNU Automake 1.5, the flags @option{-dlopen}
1996 or @option{-dlpreopen} (@pxref{Link mode}) can be employed with the
1997 @samp{program_LDADD} variable.  Unfortunately, older releases didn't
1998 accept these flags, so if you are stuck with an ancient Automake, we
1999 recommend quoting the flag itself, and setting
2000 @samp{program_DEPENDENCIES} too:
2002 @example
2003 program_LDADD = "-dlopen" libfoo.la
2004 program_DEPENDENCIES = libfoo.la
2005 @end example
2007 } variable:
2009 @example
2010 bin_PROGRAMS = hell hell_static
2012 # Build hell from main.c and libhello.la
2013 hell_SOURCES = main.c
2014 hell_LDADD = libhello.la
2016 # Create a statically linked version of hell.
2017 hell_static_SOURCES = main.c
2018 hell_static_LDADD = libhello.la
2019 hell_static_LDFLAGS = -static
2020 @end example
2022 You may use the @samp{program_LDFLAGS} variable to stuff in any flags
2023 you want to pass to libtool while linking @file{program} (such as
2024 @option{-static} to avoid linking uninstalled shared libtool libraries).
2026 Building a libtool library is almost as trivial@dots{} note the use of
2027 @samp{libhello_la_LDFLAGS} to pass the @option{-version-info}
2028 (@pxref{Versioning}) option to libtool:
2030 @example
2031 # Build a libtool library, libhello.la for installation in libdir.
2032 lib_LTLIBRARIES = libhello.la
2033 libhello_la_SOURCES = hello.c foo.c
2034 libhello_la_LDFLAGS = -version-info 3:12:1
2035 @end example
2037 The @option{-rpath} option is passed automatically by Automake (except for
2038 libraries listed as @code{noinst_LTLIBRARIES}), so you
2039 should not specify it.
2041 @xref{A Shared Library, Building a Shared Library, The Automake Manual,
2042 automake, The Automake Manual}, for more information.
2044 When building libtool archives which depend on built sources (for example a
2045 generated header file), you may find it necessary to manually record
2046 these dependencies.
2047 Because libtool archives generate object file names manually recording these
2048 dependencies is not as straightforward as the examples in Automake's manual
2049 describe in their examples.
2050 This effects header files in particular, because simply listing them as
2051 @samp{nodist_libfoo_la_SOURCES} will not cause Automake to establish a
2052 dependent relationship for the object files of @file{libfoo.la}.
2053 A useful trick (although somewhat imprecise) is to manually record built
2054 sources used by a libtool archive as dependencies of all the objects for that
2055 library as shown below (as opposed to a particular object file):
2057 @example
2058 # Build a libtool library, libhello.la which depends on a generated header.
2059 hello.h:
2060         echo '#define HELLO_MESSAGE  "Hello, World!"' > $@@
2061 BUILT_SOURCES = hello.h
2062 CLEANFILES = hello.h
2063 nodist_libhello_la_SOURCES = hello.h
2064 libhello_la_SOURCES = hello.c foo.h foo.c bar.h bar.c
2065 # Manually record hello.h as a prerequisite for all objects in libhello.la
2066 $(libhello_la_OBJECTS): hello.h
2067 @end example
2069 @xref{Built Sources Example, Recording Dependencies manually, The Automake Manual,
2070 automake, The Automake Manual}, for more information.
2072 @node Configuring
2073 @section Configuring libtool
2074 @cindex configuring libtool
2076 Libtool requires intimate knowledge of your compiler suite and operating
2077 system to be able to create shared libraries and link against
2078 them properly.  When you install the libtool distribution, a
2079 system-specific libtool script is installed into your binary directory.
2081 However, when you distribute libtool with your own packages
2082 (@pxref{Distributing}), you do not always know the compiler suite and
2083 operating system that are used to compile your package.
2085 For this reason, libtool must be @dfn{configured} before it can be
2086 used.  This idea should be familiar to anybody who has used a GNU
2087 @code{configure} script.  @code{configure} runs a number of tests for
2088 system features, then generates the @file{Makefile}s (and possibly a
2089 @file{config.h} header file), after which you can run @code{make} and
2090 build the package.
2092 Libtool adds its own tests to your @code{configure} script to
2093 generate a libtool script for the installer's host machine.
2095 @menu
2096 * LT_INIT::                     Configuring @code{libtool} in @file{configure.ac}.
2097 * Configure notes::             Platform-specific notes for configuration.
2098 @end menu
2100 @node LT_INIT
2101 @subsection The @code{LT_INIT} macro
2103 If you are using GNU Autoconf (or Automake), you should add a call to
2104 @code{LT_INIT} to your @file{configure.ac} file.  This macro
2105 adds many new tests to the @code{configure} script so that the generated
2106 libtool script will understand the characteristics of the host.  It's the
2107 most important of a number of macros defined by Libtool:
2109 @defmac LT_PREREQ (@var{version})
2110 Ensure that a recent enough version of Libtool is being used.  If the
2111 version of Libtool used for @code{LT_INIT} is earlier than
2112 @var{version}, print an error message to the standard
2113 error output and exit with failure (exit status is 63).  For example:
2115 @example
2116 LT_PREREQ([@value{VERSION}])
2117 @end example
2118 @end defmac
2120 @defmac LT_INIT (@var{options})
2121 @defmacx AC_PROG_LIBTOOL
2122 @defmacx AM_PROG_LIBTOOL
2123 Add support for the @option{--enable-shared}, @option{--disable-shared},
2124 @option{--enable-static}, @option{--disable-static}, @option{--with-pic}, and
2125 @option{--without-pic} @code{configure} flags.@footnote{@code{LT_INIT} requires
2126 that you define the @file{Makefile} variable @code{top_builddir} in your
2127 @file{Makefile.in}.  Automake does this automatically, but Autoconf
2128 users should set it to the relative path to the top of your build
2129 directory (@file{../..}, for example).}  @code{AC_PROG_LIBTOOL} and
2130 @code{AM_PROG_LIBTOOL} are deprecated names for older versions of this macro;
2131 @code{autoupdate} will upgrade your @file{configure.ac} files.
2133 By default, this macro turns on shared libraries if they are available,
2134 and also enables static libraries if they don't conflict with the shared
2135 libraries.  You can modify these defaults by passing either
2136 @code{disable-shared} or @code{disable-static} in the option list to
2137 @code{LT_INIT}, or using @code{AC_DISABLE_SHARED} or @code{AC_DISABLE_STATIC}.
2139 @example
2140 # Turn off shared libraries during beta-testing, since they
2141 # make the build process take too long.
2142 LT_INIT([disable-shared])
2143 @end example
2145 The user may specify modified forms of the configure flags
2146 @option{--enable-shared} and @option{--enable-static} to choose whether
2147 shared or static libraries are built based on the name of the package.
2148 For example, to have shared @samp{bfd} and @samp{gdb} libraries built,
2149 but not shared @samp{libg++}, you can run all three @code{configure}
2150 scripts as follows:
2152 @example
2153 trick$ ./configure --enable-shared=bfd,gdb
2154 @end example
2156 In general, specifying @option{--enable-shared=@var{pkgs}} is the same as
2157 configuring with @option{--enable-shared} every package named in the
2158 comma-separated @var{pkgs} list, and every other package with
2159 @option{--disable-shared}.  The @option{--enable-static=@var{pkgs}} flag
2160 behaves similarly, but it uses @option{--enable-static} and
2161 @option{--disable-static}.  The same applies to the
2162 @option{--enable-fast-install=@var{pkgs}} flag, which uses
2163 @option{--enable-fast-install} and @option{--disable-fast-install}.
2165 The package name @samp{default} matches any packages that have not set
2166 their name in the @code{PACKAGE} environment variable.
2168 The @option{--with-pic} and @option{--without-pic} configure flags can be used
2169 to specify whether or not @command{libtool} uses PIC objects.  By default,
2170 @command{libtool} uses PIC objects for shared libraries and non-PIC objects for
2171 static libraries.  The @option{--with-pic} option also accepts a comma-separated
2172 list of package names.  Specifying @option{--with-pic=@var{pkgs}} is the same
2173 as configuring every package in @var{pkgs} with @option{--with-pic} and every
2174 other package with the default configuration.  The package name @samp{default}
2175 is treated the same as for @option{--enable-shared} and
2176 @option{--enable-static}.
2178 This macro also sets the shell variable @code{LIBTOOL_DEPS}, that you
2179 can use to automatically update the libtool script if it becomes
2180 out-of-date.  In order to do that, add to your @file{configure.ac}:
2182 @example
2183 LT_INIT
2184 AC_SUBST([LIBTOOL_DEPS])
2185 @end example
2187 and, to @file{Makefile.in} or @file{Makefile.am}:
2189 @example
2190 LIBTOOL_DEPS = @@LIBTOOL_DEPS@@
2191 libtool: $(LIBTOOL_DEPS)
2192         $(SHELL) ./config.status libtool
2193 @end example
2195 If you are using GNU Automake, you can omit the assignment, as Automake
2196 will take care of it.  You'll obviously have to create some dependency
2197 on @file{libtool}.
2199 Aside from @code{disable-static} and @code{disable-shared}, there are
2200 other options that you can pass to @code{LT_INIT} to modify its
2201 behaviour.  Here is a full list:
2203 @table @samp
2204 @item dlopen
2205 Enable checking for dlopen support.  This option should be used if
2206 the package makes use of the @option{-dlopen} and @option{-dlpreopen}
2207 libtool flags, otherwise libtool will assume that the system does not
2208 support dlopening.
2210 @item win32-dll
2211 This option should be used if the package has been ported to build clean
2212 dlls on win32 platforms.  Usually this means that any library data items
2213 are exported with @code{__declspec(dllexport)} and imported with
2214 @code{__declspec(dllimport)}.  If this option is not used, libtool will
2215 assume that the package libraries are not dll clean and will build only
2216 static libraries on win32 hosts.
2218 Provision must be made to pass @option{-no-undefined} to @code{libtool}
2219 in link mode from the package @code{Makefile}.  Naturally, if you pass
2220 @option{-no-undefined}, you must ensure that all the library symbols
2221 @strong{really are} defined at link time!
2223 @item aix-soname=aix
2224 @itemx aix-soname=svr4
2225 @itemx aix-soname=both
2226 Enable the @option{--with-aix-soname} to @command{configure}, which the
2227 user can pass to override the given default.
2229 By default (and @strong{always} in releases prior to 2.4.4), Libtool always
2230 behaves as if @code{aix-soname=aix} is given, with no @command{configure}
2231 option for the user to override. Specifically, when the @option{-brtl} linker
2232 flag is seen in @code{LDFLAGS} at build-time, static archives are built from
2233 static objects only, otherwise, traditional AIX shared library archives of
2234 shared objects using in-archive versioning are built (with the @code{.a} file
2235 extension!). Similarly, with @option{-brtl} in @code{LDFLAGS}, libtool
2236 shared archives are built from shared objects, without any filename-based
2237 versioning; and without @option{-brtl} no shared archives are built at all.
2239 When @code{aix-soname=svr4} option is given, or the
2240 @option{--with-aix-soname=svr4} @command{configure} option is passed, static
2241 archives are always created from static objects, even without @option{-brtl}
2242 in @code{LDFLAGS}. Shared archives are made from shared objects, and filename
2243 based versioning is enabled.
2245 When @code{aix-soname=both} option is given, or the
2246 @option{--with-aix-soname=svr4} @command{configure} option is passed, static
2247 archives are built traditionally (as @option{aix-soname=aix}), and both
2248 kinds of shared archives are built. The @code{.la} pseudo-archive specifies
2249 one or the other depending on whether @option{-brtl} is specified in
2250 @code{LDFLAGS} when the library is built.
2252 @item disable-fast-install
2253 Change the default behaviour for @code{LT_INIT} to disable
2254 optimization for fast installation.  The user may still override this
2255 default, depending on platform support, by specifying
2256 @option{--enable-fast-install} to @command{configure}.
2258 @item shared
2259 Change the default behaviour for @code{LT_INIT} to enable
2260 shared libraries.  This is the default on all systems where
2261 Libtool knows how to create shared libraries.
2262 The user may still override this default by specifying
2263 @option{--disable-shared} to @command{configure}.
2265 @item disable-shared
2266 Change the default behaviour for @code{LT_INIT} to disable
2267 shared libraries.  The user may still override this default by
2268 specifying @option{--enable-shared} to @command{configure}.
2270 @item static
2271 Change the default behaviour for @code{LT_INIT} to enable
2272 static libraries.  This is the default on all systems where
2273 shared libraries have been disabled for some reason, and on
2274 most systems where shared libraries have been enabled.
2275 If shared libraries are enabled, the user may still override
2276 this default by specifying @option{--disable-static} to
2277 @command{configure}.
2279 @item disable-static
2280 Change the default behaviour for @code{LT_INIT} to disable
2281 static libraries.  The user may still override this default by
2282 specifying @option{--enable-static} to @command{configure}.
2284 @item pic-only
2285 Change the default behaviour for @command{libtool} to try to use only
2286 PIC objects.  The user may still override this default by specifying
2287 @option{--without-pic} to @command{configure}.
2289 @item no-pic
2290 Change the default behaviour of @command{libtool} to try to use only
2291 non-PIC objects.  The user may still override this default by
2292 specifying @option{--with-pic} to @command{configure}.
2294 @end table
2296 @end defmac
2298 @defmac LT_LANG (@var{language})
2299 Enable @command{libtool} support for the language given if it
2300 has not yet already been enabled.  Languages accepted are ``C++'',
2301 ``Fortran 77'', ``Java'', ``Go'', and ``Windows Resource''.
2303 If Autoconf language support macros such as @code{AC_PROG_CXX} are
2304 used in your @file{configure.ac}, Libtool language support will automatically
2305 be enabled.
2307 Conversely using @code{LT_LANG} to enable language support for Libtool
2308 will automatically enable Autoconf language support as well.
2310 Both of the following examples are therefore valid ways of adding C++
2311 language support to Libtool.
2313 @example
2314 LT_INIT
2315 LT_LANG([C++])
2316 @end example
2318 @example
2319 LT_INIT
2320 AC_PROG_CXX
2321 @end example
2323 @end defmac
2325 @defmac AC_LIBTOOL_DLOPEN
2326 This macro is deprecated, the @samp{dlopen} option to @code{LT_INIT} should be
2327 used instead.
2328 @end defmac
2330 @defmac AC_LIBTOOL_WIN32_DLL
2331 This macro is deprecated, the @samp{win32-dll} option to @code{LT_INIT} should
2332 be used instead.
2333 @end defmac
2335 @defmac AC_DISABLE_FAST_INSTALL
2336 This macro is deprecated, the @samp{disable-fast-install} option to @code{LT_INIT}
2337 should be used instead.
2338 @end defmac
2340 @defmac AC_DISABLE_SHARED
2341 @defmacx AM_DISABLE_SHARED
2342 Change the default behaviour for @code{LT_INIT} to disable shared libraries.
2343 The user may still override this default by specifying @samp{--enable-shared}.
2344 The option @samp{disable-shared} to @code{LT_INIT} is a shorthand for this.
2345 @code{AM_DISABLE_SHARED} is a deprecated alias for @code{AC_DISABLE_SHARED}.
2346 @end defmac
2348 @defmac AC_ENABLE_SHARED
2349 @defmacx AM_ENABLE_SHARED
2350 Change the default behaviour for @code{LT_INIT} to enable shared libraries.
2351 This is the default on all systems where Libtool knows how to create
2352 shared libraries.  The user may still override this default by specifying
2353 @samp{--disable-shared}.  The option @samp{shared} to @code{LT_INIT} is a
2354 shorthand for this.
2355 @code{AM_ENABLE_SHARED} is a deprecated alias for @code{AC_ENABLE_SHARED}.
2356 @end defmac
2358 @defmac AC_DISABLE_STATIC
2359 @defmacx AM_DISABLE_STATIC
2360 Change the default behaviour for @code{LT_INIT} to disable static libraries.
2361 The user may still override this default by specifying @samp{--enable-static}.
2362 The option @samp{disable-static} to @code{LT_INIT} is a shorthand for this.
2363 @code{AM_DISABLE_STATIC} is a deprecated alias for @code{AC_DISABLE_STATIC}.
2364 @end defmac
2366 @defmac AC_ENABLE_STATIC
2367 @defmacx AM_ENABLE_STATIC
2368 Change the default behaviour for @code{LT_INIT} to enable static libraries.
2369 This is the default on all systems where shared libraries have been disabled
2370 for some reason, and on most systems where shared libraries have been enabled.
2371 If shared libraries are enabled, the user may still override this default by
2372 specifying @samp{--disable-static}.  The option @samp{static} to @code{LT_INIT}
2373 is a shorthand for this.
2374 @code{AM_ENABLE_STATIC} is a deprecated alias for @code{AC_ENABLE_STATIC}.
2375 @end defmac
2377 The tests in @code{LT_INIT} also recognize the following
2378 environment variables:
2380 @defvar CC
2381 The C compiler that will be used by the generated @code{libtool}.  If
2382 this is not set, @code{LT_INIT} will look for @command{gcc} or
2383 @command{cc}.
2384 @end defvar
2386 @defvar CFLAGS
2387 Compiler flags used to generate standard object files.  If this is not
2388 set, @code{LT_INIT} will not use any such flags.  It affects
2389 only the way @code{LT_INIT} runs tests, not the produced
2390 @code{libtool}.
2391 @end defvar
2393 @defvar CPPFLAGS
2394 C preprocessor flags.  If this is not set, @code{LT_INIT} will
2395 not use any such flags.  It affects only the way @code{LT_INIT}
2396 runs tests, not the produced @code{libtool}.
2397 @end defvar
2399 @defvar LD
2400 The system linker to use (if the generated @code{libtool} requires one).
2401 If this is not set, @code{LT_INIT} will try to find out what is
2402 the linker used by @code{CC}.
2403 @end defvar
2405 @defvar LDFLAGS
2406 The flags to be used by @code{libtool} when it links a program.  If
2407 this is not set, @code{LT_INIT} will not use any such flags.  It
2408 affects only the way @code{LT_INIT} runs tests, not the produced
2409 @code{libtool}.
2410 @end defvar
2412 @defvar LIBS
2413 The libraries to be used by @code{LT_INIT} when it links a
2414 program.  If this is not set, @code{LT_INIT} will not use any
2415 such flags.  It affects only the way @code{LT_INIT} runs tests,
2416 not the produced @code{libtool}.
2417 @end defvar
2419 @defvar NM
2420 Program to use rather than checking for @command{nm}.
2421 @end defvar
2423 @defvar RANLIB
2424 Program to use rather than checking for @command{ranlib}.
2425 @end defvar
2427 @defvar LN_S
2428 A command that creates a link of a program, a soft-link if possible, a
2429 hard-link otherwise.  @code{LT_INIT} will check for a suitable
2430 program if this variable is not set.
2431 @end defvar
2433 @defvar DLLTOOL
2434 Program to use rather than checking for @command{dlltool}.  Only meaningful
2435 for Cygwin/MS-Windows.
2436 @end defvar
2438 @defvar OBJDUMP
2439 Program to use rather than checking for @command{objdump}.  Only meaningful
2440 for Cygwin/MS-Windows.
2441 @end defvar
2443 @defvar AS
2444 Program to use rather than checking for @command{as}.  Only used on
2445 Cygwin/MS-Windows at the moment.
2446 @end defvar
2448 @defvar MANIFEST_TOOL
2449 Program to use rather than checking for @command{mt}, the Manifest Tool.
2450 Only used on Cygwin/MS-Windows at the moment.
2451 @end defvar
2453 @defvar LT_SYS_LIBRARY_PATH
2454 Libtool has heuristics for the system search path for runtime-loaded
2455 libraries.  If the guessed default does not match the setup of the host
2456 system, this variable can be used to modify that path list, as follows
2457 (@code{LT_SYS_LIBRARY_PATH} is a colon-delimited list like @code{PATH}):
2458 @itemize @bullet
2459 @item @code{path:}
2460 The heuristically determined paths will be appened after the trailing
2461 colon;
2462 @item @code{:path}
2463 The heuristically determined paths will be prepended before the leading
2464 colon;
2465 @item @code{path::path}
2466 The heuristically determined paths will be inserted between the double
2467 colons;
2468 @item @code{path}
2469 With no dangling colons, the heuristically determined paths will be
2470 ignored entirely.
2471 @end itemize
2472 @end defvar
2474 With 1.3 era libtool, if you wanted to know any details of what
2475 libtool had discovered about your architecture and environment, you
2476 had to run the script with @option{--config} and grep through the
2477 results.  This idiom was supported up to and including 1.5.x era
2478 libtool, where it was possible to call the generated libtool script
2479 from @file{configure.ac} as soon as @code{LT_INIT} had
2480 completed.  However, one of the features of libtool 1.4 was that the
2481 libtool configuration was migrated out of a separate @file{ltconfig}
2482 file, and added to the @code{LT_INIT} macro (nee @code{AC_PROG_LIBTOOL}),
2483 so the results of the configuration tests were available directly to code in
2484 @file{configure.ac}, rendering the call out to the generated libtool
2485 script obsolete.
2487 Starting with libtool 2.0, the multipass generation of the libtool
2488 script has been consolidated into a single @file{config.status} pass,
2489 which happens after all the code in @file{configure.ac} has
2490 completed.  The implication of this is that the libtool script does
2491 not exist during execution of code from @file{configure.ac}, and so
2492 obviously it cannot be called for @option{--config} details anymore.  If
2493 you are upgrading projects that used this idiom to libtool 2.0 or
2494 newer, you should replace those calls with direct references to the
2495 equivalent Autoconf shell variables that are set by the configure time
2496 tests before being passed to @file{config.status} for inclusion in the
2497 generated libtool script.
2499 @defmac LT_OUTPUT
2500 By default, the configured @file{libtool} script is generated by the
2501 call to @code{AC_OUTPUT} command, and there is rarely any need to use
2502 @file{libtool} from @file{configure}.  However, sometimes it is
2503 necessary to run configure time compile and link tests using
2504 @file{libtool}.  You can add @code{LT_OUTPUT} to your
2505 @file{configure.ac} any time after @code{LT_INIT} and any
2506 @code{LT_LANG} calls; that done, @file{libtool} will be created by a
2507 specially generated @file{config.lt} file, and available for use in
2508 later tests.
2510 Also, when @code{LT_OUTPUT} is used, for backwards compatibility with
2511 Automake regeneration rules, @file{config.status} will call
2512 @file{config.lt} to regenerate @file{libtool}, rather than generating
2513 the file itself.
2514 @end defmac
2516 @pindex aclocal
2517 When you invoke the @command{libtoolize} program (@pxref{Invoking
2518 libtoolize}), it will tell you where to find a definition of
2519 @code{LT_INIT}.  If you use Automake, the @command{aclocal} program
2520 will automatically add @code{LT_INIT} support to your
2521 @file{configure} script when it sees the invocation of @code{LT_INIT}
2522 in @file{configure.ac}.
2524 Because of these changes, and the runtime version compatibility checks
2525 Libtool now executes, we now advise @strong{against} including a copy of
2526 @file{libtool.m4} (and brethren) in @file{acinclude.m4}.  Instead,
2527 you should set your project macro directory with
2528 @code{AC_CONFIG_MACRO_DIRS}.  When you @command{libtoolize} your
2529 project, a copy of the relevant macro definitions will be placed in
2530 your @code{AC_CONFIG_MACRO_DIRS}, where @command{aclocal} can reference
2531 them directly from @file{aclocal.m4}.
2534 @node Configure notes
2535 @subsection Platform-specific configuration notes
2537 While Libtool tries to hide as many platform-specific features as possible,
2538 some have to be taken into account when configuring either the Libtool package
2539 or a libtoolized package.
2541 @include notes.texi
2544 @node Distributing
2545 @section Including libtool in your package
2547 In order to use libtool, you need to include the following files with
2548 your package:
2550 @table @file
2551 @item config.guess
2552 @pindex config.guess
2553 Attempt to guess a canonical system name.
2555 @item config.sub
2556 @pindex config.sub
2557 Canonical system name validation subroutine script.
2559 @item install-sh
2560 @pindex install-sh
2561 BSD-compatible @command{install} replacement script.
2563 @item ltmain.sh
2564 @pindex ltmain.sh
2565 A generic script implementing basic libtool functionality.
2566 @end table
2568 Note that the libtool script itself should @emph{not} be included with
2569 your package.  @xref{Configuring}.
2571 You should use the @command{libtoolize} program, rather than manually
2572 copying these files into your package.
2574 @menu
2575 * Invoking libtoolize::         @code{libtoolize} command line options.
2576 * Autoconf and LTLIBOBJS::      Autoconf automates LTLIBOBJS generation.
2577 @end menu
2579 @node Invoking libtoolize
2580 @subsection Invoking @command{libtoolize}
2581 @pindex libtoolize
2582 @cindex libtoolize command options
2583 @cindex command options, libtoolize
2584 @cindex options, libtoolize command
2586 The @command{libtoolize} program provides a standard way to add libtool
2587 support to your package.  In the future, it may implement better usage
2588 checking, or other features to make libtool even easier to use.
2590 The @command{libtoolize} program has the following synopsis:
2592 @example
2593 libtoolize [@var{option}]@dots{}
2594 @end example
2596 @noindent
2597 and accepts the following options:
2599 @table @option
2601 @item --copy
2602 @itemx -c
2603 Copy files from the libtool data directory rather than creating
2604 symlinks.
2606 @item --debug
2607 Dump a trace of shell script execution to standard output.  This
2608 produces a lot of output, so you may wish to pipe it to @command{less} (or
2609 @command{more}) or redirect to a file.
2611 @item --dry-run
2612 @itemx -n
2613 Don't run any commands that modify the file system, just print them
2614 out.
2616 @item --force
2617 @itemx -f
2618 Replace existing libtool files.  By default, @command{libtoolize} won't
2619 overwrite existing files.
2621 @item --help
2622 Display a help message and exit.
2624 @item --ltdl [@var{target-directory-name}]
2625 Install libltdl in the @var{target-directory-name} subdirectory of
2626 your package.  Normally, the directory is extracted from the argument
2627 to @code{LT_CONFIG_LTDL_DIR} in @file{configure.ac}, though you can
2628 also specify a subdirectory name here if you are not using Autoconf
2629 for example.  If @command{libtoolize} can't determine the target
2630 directory, @samp{libltdl} is used as the default.
2632 @item --no-warn
2633 Normally, Libtoolize tries to diagnose use of deprecated libtool macros
2634 and other stylistic issues.  If you are deliberately using outdated
2635 calling conventions, this option prevents Libtoolize from explaining
2636 how to update your project's Libtool conventions.
2638 @item --nonrecursive
2639 If passed in conjunction with @option{--ltdl}, this option will cause
2640 the @command{libltdl} installed by @samp{libtoolize} to be set up for
2641 use with a non-recursive @command{automake} build.  To make use of it,
2642 you will need to add the following to the @file{Makefile.am} of the
2643 parent project:
2645 @example
2646 ## libltdl/ltdl.mk @r{appends to the following variables}
2647 ## @r{so we set them here before including it:}
2648 BUILT_SOURCES   =
2650 AM_CPPFLAGS        =
2651 AM_LDFLAGS         =
2653 include_HEADERS    =
2654 noinst_LTLIBRARIES =
2655 lib_LTLIBRARIES   =
2656 EXTRA_LTLIBRARIES  =
2658 EXTRA_DIST   =
2660 CLEANFILES   =
2661 MOSTLYCLEANFILES   =
2663 include libltdl/ltdl.mk
2664 @end example
2666 @noindent
2668 @item --quiet
2669 @itemx -q
2670 Work silently.  @samp{libtoolize --quiet} is used by GNU Automake
2671 to add libtool files to your package if necessary.
2673 @item --recursive
2674 If passed in conjunction with @option{--ltdl}, this option will cause
2675 the @command{libtoolize} installed @samp{libltdl} to be set up for use
2676 with a recursive @command{automake} build.  To make use of it, you
2677 will need to adjust the parent project's @file{configure.ac}:
2679 @example
2680 AC_CONFIG_FILES([libltdl/Makefile])
2681 @end example
2683 @noindent
2684 and @file{Makefile.am}:
2686 @example
2687 SUBDIRS += libltdl
2688 @end example
2690 @item --subproject
2691 If passed in conjunction with @option{--ltdl}, this option will cause
2692 the @command{libtoolize} installed @samp{libltdl} to be set up for
2693 independent configuration and compilation as a self-contained
2694 subproject.  To make use of it, you should arrange for your build to
2695 call @command{libltdl/configure}, and then run @command{make} in the
2696 @file{libltdl} directory (or the subdirectory you put libltdl into).
2697 If your project uses Autoconf, you can use the supplied
2698 @samp{LT_WITH_LTDL} macro, or else call @samp{AC_CONFIG_SUBDIRS}
2699 directly.
2701 Previous releases of @samp{libltdl} built exclusively in this mode,
2702 but now it is the default mode both for backwards compatibility and
2703 because, for example, it is suitable for use in projects that wish to
2704 use @samp{libltdl}, but not use the Autotools for their own build
2705 process.
2707 @item --verbose
2708 @itemx -v
2709 Work noisily!  Give a blow by blow account of what
2710 @command{libtoolize} is doing.
2712 @item --version
2713 Print @command{libtoolize} version information and exit.
2714 @end table
2716 @cindex LIBTOOLIZE_OPTIONS
2717 Sometimes it can be useful to pass options to @command{libtoolize} even
2718 though it is called by another program, such as @command{autoreconf}.  A
2719 limited number of options are parsed from the environment variable
2720 @code{LIBTOOLIZE_OPTIONS}: currently @option{--debug}, @option{--no-warn},
2721 @option{--quiet} and @option{--verbose}.  Multiple options passed in
2722 @code{LIBTOOLIZE_OPTIONS} must be separated with a space, comma or a
2723 colon.
2725 By default, a warning is issued for unknown options found in
2726 @code{LIBTOOLIZE_OPTIONS} unless the first such option is
2727 @option{--no-warn}.  Where @command{libtoolize} has always quit
2728 on receipt of an unknown option at the command line, this and all
2729 previous releases of @command{libtoolize} will continue unabated whatever
2730 the content of @code{LIBTOOLIZE_OPTIONS} (modulo some possible warning
2731 messages).
2733 @example
2734 trick$ @kbd{LIBTOOLIZE_OPTIONS=--no-warn,--quiet autoreconf --install}
2735 @end example
2737 @findex AC_CONFIG_MACRO_DIRS
2738 If @command{libtoolize} detects an explicit call to
2739 @code{AC_CONFIG_MACRO_DIRS} (@pxref{Input, , The Autoconf Manual,
2740 autoconf, The Autoconf Manual}) in your @file{configure.ac}, it will
2741 put the Libtool macros in the specified directory.
2743 In the future other Autotools will automatically check the contents of
2744 @code{AC_CONFIG_MACRO_DIRS}, but at the moment it is more portable to
2745 add the macro directory to @code{ACLOCAL_AMFLAGS} in
2746 @file{Makefile.am}, which is where the tools currently look.  If
2747 @command{libtoolize} doesn't see @code{AC_CONFIG_MACRO_DIRS}, it too
2748 will honour the first @samp{-I} argument in @code{ACLOCAL_AMFLAGS}
2749 when choosing a directory to store libtool configuration macros in.
2750 It is perfectly sensible to use both @code{AC_CONFIG_MACRO_DIRS} and
2751 @code{ACLOCAL_AMFLAGS}, as long as they are kept in synchronisation.
2753 @example
2754 ACLOCAL_AMFLAGS = -I m4
2755 @end example
2757 When you bootstrap your project with @command{aclocal}, then you will
2758 need to explicitly pass the same macro directory with
2759 @command{aclocal}'s @samp{-I} flag:
2761 @example
2762 trick$ @kbd{aclocal -I m4}
2763 @end example
2765 @findex AC_CONFIG_AUX_DIR
2766 If @command{libtoolize} detects an explicit call to
2767 @code{AC_CONFIG_AUX_DIR} (@pxref{Input, , The Autoconf Manual,
2768 autoconf, The Autoconf Manual}) in your @file{configure.ac}, it
2769 will put the other support files in the specified directory.
2770 Otherwise they too end up in the project root directory.
2772 Unless @option{--no-warn} is passed, @command{libtoolize} displays
2773 hints for adding libtool support to your package, as well.
2775 @node Autoconf and LTLIBOBJS
2776 @subsection Autoconf and @code{LTLIBOBJS}
2778 People used to add code like the following to their
2779 @file{configure.ac}:
2781 @cindex LTLIBOBJS
2782 @example
2783 LTLIBOBJS=`echo "$LIBOBJS" | sed 's/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'`
2784 AC_SUBST([LTLIBOBJS])
2785 @end example
2787 @noindent
2788 This is no longer required (since Autoconf 2.54), and doesn't take
2789 Automake's deansification support into account either, so doesn't work
2790 correctly even with ancient Autoconfs!
2792 Provided you are using a recent (2.54 or better) incarnation of
2793 Autoconf, the call to @code{AC_OUTPUT} takes care of setting
2794 @code{LTLIBOBJS} up correctly, so you can simply delete such snippets
2795 from your @file{configure.ac} if you had them.
2798 @node Static-only libraries
2799 @section Static-only libraries
2800 @cindex debugging libraries
2801 @cindex developing libraries
2802 @cindex double-compilation, avoiding
2803 @cindex avoiding shared libraries
2804 @cindex eliding shared libraries
2805 @cindex using shared libraries, not
2806 @cindex shared libraries, not using
2807 @cindex time, saving
2808 @cindex saving time
2810 When you are developing a package, it is often worthwhile to configure
2811 your package with the @option{--disable-shared} flag, or to override the
2812 defaults for @code{LT_INIT} by using the @code{disable-shared} option
2813 (@pxref{LT_INIT, , The @code{LT_INIT} macro}).  This prevents libtool
2814 from building shared libraries, which has several advantages:
2816 @itemize @bullet
2817 @item
2818 compilation is twice as fast, which can speed up your development cycle,
2820 @item
2821 debugging is easier because you don't need to deal with any complexities
2822 added by shared libraries, and
2824 @item
2825 you can see how libtool behaves on static-only platforms.
2826 @end itemize
2828 You may want to put a small note in your package @file{README} to let
2829 other developers know that @option{--disable-shared} can save them time.
2830 The following example note is taken from the GIMP@footnote{GNU Image
2831 Manipulation Program, for those who haven't taken the plunge.  See
2832 @url{http://www.gimp.org/}.} distribution @file{README}:
2834 @example
2835 The GIMP uses GNU Libtool to build shared libraries on a
2836 variety of systems.  While this is very nice for making usable
2837 binaries, it can be a pain when trying to debug a program.  For that
2838 reason, compilation of shared libraries can be turned off by
2839 specifying the @option{--disable-shared} option to @file{configure}.
2840 @end example
2843 @node Other languages
2844 @chapter Using libtool with other languages
2845 @cindex C, not using
2846 @cindex languages, non-C
2847 @cindex C++, using
2849 Libtool was first implemented to add support for writing shared
2850 libraries in the C language.  However, over time, libtool is being
2851 integrated with other languages, so that programmers are free to reap
2852 the benefits of shared libraries in their favorite programming language.
2854 This chapter describes how libtool interacts with other languages,
2855 and what special considerations you need to make if you do not use C.
2857 @menu
2858 * C++ libraries::               Writing libraries for C++
2859 * Tags::                        Tags
2860 @end menu
2862 @node C++ libraries
2863 @section Writing libraries for C++
2864 @c FIXME: in the TOC, the ++ is too large (seems to be math mode)
2865 @cindex trouble with C++
2866 @cindex pitfalls using C++
2867 @cindex C++, pitfalls
2869 Creating libraries of C++ code should be a fairly straightforward
2870 process, because its object files differ from C ones in only three ways:
2872 @enumerate 1
2873 @item
2874 Because of name mangling, C++ libraries are only usable by the C++
2875 compiler that created them.  This decision was made by the designers of
2876 C++ to protect users from conflicting implementations of
2877 features such as constructors, exception handling, and RTTI.
2879 @item
2880 On some systems, the C++ compiler must take special actions for the
2881 dynamic linker to run dynamic (i.e., run-time) initializers.  This means
2882 that we should not call @command{ld} directly to link such libraries, and
2883 we should use the C++ compiler instead.
2885 @item
2886 C++ compilers will link some Standard C++ library in by default, but
2887 libtool does not know what these libraries are, so it cannot even run
2888 the inter-library dependence analyzer to check how to link it in.
2889 Therefore, running @command{ld} to link a C++ program or library is deemed
2890 to fail.
2891 @end enumerate
2893 Because of these three issues, Libtool has been designed to always use
2894 the C++ compiler to compile and link C++ programs and libraries.  In
2895 some instances the @code{main()} function of a program must also be
2896 compiled with the C++ compiler for static C++ objects to be properly
2897 initialized.
2899 @node Tags
2900 @section Tags
2901 @cindex tag names
2902 @cindex language names
2903 @cindex inferring tags
2905 Libtool supports multiple languages through the use of tags.  Technically
2906 a tag corresponds to a set of configuration variables associated with a
2907 language.  These variables tell @command{libtool} how it should create
2908 objects and libraries for each language.
2910 Tags are defined at @command{configure}-time for each language activated
2911 in the package (see @code{LT_LANG} in @ref{LT_INIT}).  Here is the
2912 correspondence between language names and tags names.
2914 @multitable {Windows Resource} {Tag name}
2915 @item Language name    @tab Tag name
2916 @item C                @tab CC
2917 @item C++              @tab CXX
2918 @item Java             @tab GCJ
2919 @item Fortran 77       @tab F77
2920 @item Fortran          @tab FC
2921 @item Go               @tab GO
2922 @item Windows Resource @tab RC
2923 @end multitable
2925 @command{libtool} tries to automatically infer what tag to use from
2926 the compiler command being used to compile or link.  If it can't infer
2927 a tag, then it defaults to the configuration for the @code{C} language.
2929 The tag can also be specified using @command{libtool}'s
2930 @option{--tag=@var{tag}} option (@pxref{Invoking libtool}).  It is a good
2931 idea to do so in @file{Makefile} rules, because that will allow users to
2932 substitute the compiler without relying on @command{libtool} inference
2933 heuristics.  When no tag is specified, @command{libtool} will default
2934 to @code{CC}; this tag always exists.
2936 Finally, the set of tags available in a particular project can be
2937 retrieved by tracing for the @code{LT_SUPPORTED_TAG} macro (@pxref{Trace
2938 interface}).
2940 @node Versioning
2941 @chapter Library interface versions
2942 @cindex dynamic dependencies
2943 @cindex dependency versioning
2944 @cindex shared library versions
2946 The most difficult issue introduced by shared libraries is that of
2947 creating and resolving runtime dependencies.  Dependencies on programs
2948 and libraries are often described in terms of a single name, such as
2949 @command{sed}.  So, one may say ``libtool depends on sed,'' and that is
2950 good enough for most purposes.
2952 However, when an interface changes regularly, we need to be more
2953 specific: ``Gnus 5.1 requires Emacs 19.28 or above.''  Here, the
2954 description of an interface consists of a name, and a ``version
2955 number.''
2957 Even that sort of description is not accurate enough for some purposes.
2958 What if Emacs 20 changes enough to break Gnus 5.1?
2960 The same problem exists in shared libraries: we require a formal version
2961 system to describe the sorts of dependencies that programs have on
2962 shared libraries, so that the dynamic linker can guarantee that programs
2963 are linked only against libraries that provide the interface they
2964 require.
2966 @menu
2967 * Interfaces::                  What are library interfaces?
2968 * Libtool versioning::          Libtool's versioning system.
2969 * Updating version info::       Changing version information before releases.
2970 * Release numbers::             Breaking binary compatibility for aesthetics.
2971 @end menu
2973 @node Interfaces
2974 @section What are library interfaces?
2975 @cindex library interfaces
2977 Interfaces for libraries may be any of the following (and more):
2979 @itemize @bullet
2980 @item
2981 global variables: both names and types
2983 @item
2984 global functions: argument types and number, return types, and function names
2986 @item
2987 standard input, standard output, standard error, and file formats
2989 @item
2990 sockets, pipes, and other inter-process communication protocol formats
2991 @end itemize
2993 Note that static functions do not count as interfaces, because they are
2994 not directly available to the user of the library.
2996 @node Libtool versioning
2997 @section Libtool's versioning system
2998 @cindex libtool library versions
2999 @cindex formal versioning
3000 @cindex versioning, formal
3002 Libtool has its own formal versioning system.  It is not as flexible as
3003 some, but it is definitely the simplest of the more powerful versioning
3004 systems.
3006 Think of a library as exporting several sets of interfaces, arbitrarily
3007 represented by integers.  When a program is linked against a library, it
3008 may use any subset of those interfaces.
3010 Libtool's description of the interfaces that a program uses is simple:
3011 it encodes the least and the greatest interface numbers in the resulting
3012 binary (@var{first-interface}, @var{last-interface}).
3014 The dynamic linker is guaranteed that if a library supports @emph{every}
3015 interface number between @var{first-interface} and @var{last-interface},
3016 then the program can be relinked against that library.
3018 Note that this can cause problems because libtool's compatibility
3019 requirements are actually stricter than is necessary.
3021 Say @file{libhello} supports interfaces 5, 16, 17, 18, and 19, and that
3022 libtool is used to link @file{test} against @file{libhello}.
3024 Libtool encodes the numbers 5 and 19 in @file{test}, and the dynamic
3025 linker will only link @file{test} against libraries that support
3026 @emph{every} interface between 5 and 19.  So, the dynamic linker refuses
3027 to link @file{test} against @file{libhello}!
3029 In order to eliminate this problem, libtool only allows libraries to
3030 declare consecutive interface numbers.  So, @file{libhello} can declare at
3031 most that it supports interfaces 16 through 19.  Then, the dynamic
3032 linker will link @file{test} against @file{libhello}.
3034 So, libtool library versions are described by three integers:
3036 @table @var
3037 @item current
3038 The most recent interface number that this library implements.
3040 @item revision
3041 The implementation number of the @var{current} interface.
3043 @item age
3044 The difference between the newest and oldest interfaces that this
3045 library implements.  In other words, the library implements all the
3046 interface numbers in the range from number @code{@var{current} -
3047 @var{age}} to @code{@var{current}}.
3048 @end table
3050 If two libraries have identical @var{current} and @var{age} numbers,
3051 then the dynamic linker chooses the library with the greater
3052 @var{revision} number.
3054 @node Updating version info
3055 @section Updating library version information
3057 If you want to use libtool's versioning system, then you must specify
3058 the version information to libtool using the @option{-version-info} flag
3059 during link mode (@pxref{Link mode}).
3061 This flag accepts an argument of the form
3062 @samp{@var{current}[:@var{revision}[:@var{age}]]}.  So, passing
3063 @option{-version-info 3:12:1} sets @var{current} to 3, @var{revision} to
3064 12, and @var{age} to 1.
3066 If either @var{revision} or @var{age} are omitted, they default to 0.
3067 Also note that @var{age} must be less than or equal to the @var{current}
3068 interface number.
3070 Here are a set of rules to help you update your library version
3071 information:
3073 @enumerate 1
3074 @item
3075 Start with version information of @samp{0:0:0} for each libtool library.
3077 @item
3078 Update the version information only immediately before a public release
3079 of your software.  More frequent updates are unnecessary, and only
3080 guarantee that the current interface number gets larger faster.
3082 @item
3083 If the library source code has changed at all since the last update,
3084 then increment @var{revision} (@samp{@var{c}:@var{r}:@var{a}} becomes
3085 @samp{@var{c}:@math{r+1}:@var{a}}).
3087 @item
3088 If any interfaces have been added, removed, or changed since the last
3089 update, increment @var{current}, and set @var{revision} to 0.
3091 @item
3092 If any interfaces have been added since the last public release, then
3093 increment @var{age}.
3095 @item
3096 If any interfaces have been removed or changed since the last public
3097 release, then set @var{age} to 0.
3098 @end enumerate
3100 @strong{@emph{Never}} try to set the interface numbers so that they
3101 correspond to the release number of your package.  This is an abuse that
3102 only fosters misunderstanding of the purpose of library versions.
3103 Instead, use the @option{-release} flag (@pxref{Release numbers}), but be
3104 warned that every release of your package will not be binary compatible
3105 with any other release.
3107 The following explanation may help to understand the above rules a bit
3108 better: consider that there are three possible kinds of reactions from
3109 users of your library to changes in a shared library:
3111 @enumerate 1
3112 @item
3113 Programs using the previous version may use the new version as
3114 drop-in replacement, and programs using the new version can also work
3115 with the previous one.  In other words, no recompiling nor relinking
3116 is needed.  In this case, bump @var{revision} only, don't touch
3117 @var{current} nor @var{age}.
3119 @item
3120 Programs using the previous version may use the new version as
3121 drop-in replacement, but programs using the new version may use APIs not
3122 present in the previous one.  In other words, a program linking against
3123 the new version may fail with ``unresolved symbols'' if linking against
3124 the old version at runtime: set @var{revision} to 0, bump @var{current}
3125 and @var{age}.
3127 @item
3128 Programs may need to be changed, recompiled, and relinked in order to use
3129 the new version.  Bump @var{current}, set @var{revision} and @var{age}
3130 to 0.
3131 @end enumerate
3133 @noindent
3134 In the above description, @emph{programs} using the library in question
3135 may also be replaced by other libraries using it.
3138 @node Release numbers
3139 @section Managing release information
3141 Often, people want to encode the name of the package release into the
3142 shared library so that it is obvious to the user what package their
3143 programs are linked against.  This convention is used especially on
3144 GNU/Linux:
3146 @example
3147 trick$ @kbd{ls /usr/lib/libbfd*}
3148 /usr/lib/libbfd.a           /usr/lib/libbfd.so.2.7.0.2
3149 /usr/lib/libbfd.so
3150 trick$
3151 @end example
3153 On @samp{trick}, @file{/usr/lib/libbfd.so} is a symbolic link to
3154 @file{libbfd.so.2.7.0.2}, which was distributed as a part of
3155 @samp{binutils-2.7.0.2}.
3157 Unfortunately, this convention conflicts directly with libtool's idea of
3158 library interface versions, because the library interface rarely changes
3159 at the same time that the release number does, and the library suffix is
3160 never the same across all platforms.
3162 So, to accommodate both views, you can use the @option{-release}
3163 flag to set release information for libraries for which you do not
3164 want to use @option{-version-info}.  For the @file{libbfd} example, the
3165 next release that uses libtool should be built with @samp{-release
3166 2.9.0}, which will produce the following files on GNU/Linux:
3168 @example
3169 trick$ @kbd{ls /usr/lib/libbfd*}
3170 /usr/lib/libbfd-2.9.0.so     /usr/lib/libbfd.a
3171 /usr/lib/libbfd.so
3172 trick$
3173 @end example
3175 In this case, @file{/usr/lib/libbfd.so} is a symbolic link to
3176 @file{libbfd-2.9.0.so}.  This makes it obvious that the user is dealing
3177 with @samp{binutils-2.9.0}, without compromising libtool's idea of
3178 interface versions.
3180 Note that this option causes a modification of the library name, so do
3181 not use it unless you want to break binary compatibility with any past
3182 library releases.  In general, you should only use @option{-release} for
3183 package-internal libraries or for ones whose interfaces change very
3184 frequently.
3186 @node Library tips
3187 @chapter Tips for interface design
3188 @cindex library interfaces, design
3189 @cindex design of library interfaces
3191 Writing a good library interface takes a lot of practice and thorough
3192 understanding of the problem that the library is intended to solve.
3194 If you design a good interface, it won't have to change often, you won't
3195 have to keep updating documentation, and users won't have to keep
3196 relearning how to use the library.
3198 Here is a brief list of tips for library interface design that may
3199 help you in your exploits:
3201 @table @asis
3202 @item Plan ahead
3203 Try to make every interface truly minimal, so that you won't need to
3204 delete entry points very often.
3206 @item Avoid interface changes
3207 @cindex renaming interface functions
3208 Some people love redesigning and changing entry points just for the heck
3209 of it (note: @emph{renaming} a function is considered changing an entry
3210 point).  Don't be one of those people.  If you must redesign an
3211 interface, then try to leave compatibility functions behind so that
3212 users don't need to rewrite their existing code.
3214 @item Use opaque data types
3215 @cindex opaque data types
3216 The fewer data type definitions a library user has access to, the
3217 better.  If possible, design your functions to accept a generic pointer
3218 (that you can cast to an internal data type), and provide access
3219 functions rather than allowing the library user to directly manipulate
3220 the data.
3221 That way, you have the freedom to change the data structures without
3222 changing the interface.
3224 This is essentially the same thing as using abstract data types and
3225 inheritance in an object-oriented system.
3227 @item Use header files
3228 @cindex header files
3229 If you are careful to document each of your library's global functions
3230 and variables in header files, and include them in your library source
3231 files, then the compiler will let you know if you make any interface
3232 changes by accident (@pxref{C header files}).
3234 @item Use the @code{static} keyword (or equivalent) whenever possible
3235 @cindex global functions
3236 The fewer global functions your library has, the more flexibility you'll
3237 have in changing them.  Static functions and variables may change forms
3238 as often as you like@dots{} your users cannot access them, so they
3239 aren't interface changes.
3241 @item Be careful with array dimensions
3242 The number of elements in a global array is part of an interface, even
3243 if the header just declares @code{extern int foo[];}.  This is because
3244 on i386 and some other SVR4/ELF systems, when an application
3245 references data in a shared library the size of that data (whatever
3246 its type) is included in the application executable.  If you might
3247 want to change the size of an array or string then provide a pointer
3248 not the actual array.
3249 @end table
3251 @menu
3252 * C header files::              How to write portable include files.
3253 @end menu
3255 @node C header files
3256 @section Writing C header files
3257 @cindex portable C headers
3258 @cindex C header files, portable
3259 @cindex include files, portable
3261 Writing portable C header files can be difficult, since they may be read
3262 by different types of compilers:
3264 @table @asis
3265 @item C++ compilers
3266 C++ compilers require that functions be declared with full prototypes,
3267 since C++ is more strongly typed than C@.  C functions and variables also
3268 need to be declared with the @code{extern "C"} directive, so that the
3269 names aren't mangled.  @xref{C++ libraries}, for other issues relevant
3270 to using C++ with libtool.
3272 @item ANSI C compilers
3273 ANSI C compilers are not as strict as C++ compilers, but functions
3274 should be prototyped to avoid unnecessary warnings when the header file
3275 is @code{#include}d.
3277 @item non-ANSI C compilers
3278 Non-ANSI compilers will report errors if functions are prototyped.
3279 @end table
3281 These complications mean that your library interface headers must use
3282 some C preprocessor magic to be usable by each of the above compilers.
3284 @file{foo.h} in the @file{tests/demo} subdirectory of the libtool
3285 distribution serves as an example for how to write a header file that
3286 can be safely installed in a system directory.
3288 Here are the relevant portions of that file:
3290 @example
3291 /* BEGIN_C_DECLS should be used at the beginning of your declarations,
3292    so that C++ compilers don't mangle their names.  Use END_C_DECLS at
3293    the end of C declarations. */
3294 #undef BEGIN_C_DECLS
3295 #undef END_C_DECLS
3296 #ifdef __cplusplus
3297 # define BEGIN_C_DECLS extern "C" @{
3298 # define END_C_DECLS @}
3299 #else
3300 # define BEGIN_C_DECLS /* empty */
3301 # define END_C_DECLS /* empty */
3302 #endif
3304 /* PARAMS is a macro used to wrap function prototypes, so that
3305    compilers that don't understand ANSI C prototypes still work,
3306    and ANSI C compilers can issue warnings about type mismatches. */
3307 #undef PARAMS
3308 #if defined __STDC__ || defined _AIX \
3309         || (defined __mips && defined _SYSTYPE_SVR4) \
3310         || defined WIN32 || defined __cplusplus
3311 # define PARAMS(protos) protos
3312 #else
3313 # define PARAMS(protos) ()
3314 #endif
3315 @end example
3317 These macros are used in @file{foo.h} as follows:
3319 @example
3320 #ifndef FOO_H
3321 #define FOO_H 1
3323 /* The above macro definitions. */
3324 #include "@dots{}"
3326 BEGIN_C_DECLS
3328 int foo PARAMS((void));
3329 int hello PARAMS((void));
3331 END_C_DECLS
3333 #endif /* !FOO_H */
3334 @end example
3336 Note that the @file{#ifndef FOO_H} prevents the body of @file{foo.h}
3337 from being read more than once in a given compilation.
3339 Also the only thing that must go outside the
3340 @code{BEGIN_C_DECLS}/@code{END_C_DECLS} pair are @code{#include} lines.
3341 Strictly speaking it is only C symbol names that need to be protected,
3342 but your header files will be more maintainable if you have a single
3343 pair of these macros around the majority of the header contents.
3345 You should use these definitions of @code{PARAMS}, @code{BEGIN_C_DECLS},
3346 and @code{END_C_DECLS} into your own headers.  Then, you may use them to
3347 create header files that are valid for C++, ANSI, and non-ANSI
3348 compilers@footnote{We used to recommend @code{__P},
3349 @code{__BEGIN_DECLS} and @code{__END_DECLS}.  This was bad advice since
3350 symbols (even preprocessor macro names) that begin with an underscore
3351 are reserved for the use of the compiler.}.
3353 Do not be naive about writing portable code.  Following the tips given
3354 above will help you miss the most obvious problems, but there are
3355 definitely other subtle portability issues.  You may need to cope with
3356 some of the following issues:
3358 @itemize @bullet
3359 @item
3360 Pre-ANSI compilers do not always support the @code{void *} generic
3361 pointer type, and so need to use @code{char *} in its place.
3363 @item
3364 The @code{const}, @code{inline} and @code{signed} keywords are not
3365 supported by some compilers, especially pre-ANSI compilers.
3367 @item
3368 The @code{long double} type is not supported by many compilers.
3369 @end itemize
3372 @node Inter-library dependencies
3373 @chapter Inter-library dependencies
3374 @cindex dependencies between libraries
3375 @cindex inter-library dependencies
3377 By definition, every shared library system provides a way for
3378 executables to depend on libraries, so that symbol resolution is
3379 deferred until runtime.
3381 An @dfn{inter-library dependency} is where a library depends on
3382 other libraries.  For example, if the libtool library @file{libhello}
3383 uses the @code{cos} function, then it has an inter-library dependency
3384 on @file{libm}, the math library that implements @code{cos}.
3386 Some shared library systems provide this feature in an
3387 internally-consistent way: these systems allow chains of dependencies of
3388 potentially infinite length.
3390 However, most shared library systems are restricted in that they only
3391 allow a single level of dependencies.  In these systems, programs may
3392 depend on shared libraries, but shared libraries may not depend on other
3393 shared libraries.
3395 In any event, libtool provides a simple mechanism for you to declare
3396 inter-library dependencies: for every library @file{lib@var{name}} that
3397 your own library depends on, simply add a corresponding
3398 @code{-l@var{name}} option to the link line when you create your
3399 library.  To make an example of our @file{libhello} that depends on
3400 @file{libm}:
3402 @example
3403 burger$ @kbd{libtool --mode=link gcc -g -O -o libhello.la foo.lo hello.lo \
3404                 -rpath /usr/local/lib -lm}
3405 burger$
3406 @end example
3408 When you link a program against @file{libhello}, you don't need to
3409 specify the same @samp{-l} options again: libtool will do that for you,
3410 to guarantee that all the required libraries are found.  This
3411 restriction is only necessary to preserve compatibility with static
3412 library systems and simple dynamic library systems.
3414 Some platforms, such as Windows, do not even allow you this
3415 flexibility.  In order to build a shared library, it must be entirely
3416 self-contained or it must have dependencies known at link time (that is,
3417 have references only to symbols that are found in the @file{.lo} files
3418 or the specified @samp{-l} libraries), and you need to specify the
3419 @option{-no-undefined} flag.  By default, libtool builds only static
3420 libraries on these kinds of platforms.
3422 The simple-minded inter-library dependency tracking code of libtool
3423 releases prior to 1.2 was disabled because it was not clear when it was
3424 possible to link one library with another, and complex failures would
3425 occur.  A more complex implementation of this concept was re-introduced
3426 before release 1.3, but it has not been ported to all platforms that
3427 libtool supports.  The default, conservative behavior is to avoid
3428 linking one library with another, introducing their inter-dependencies
3429 only when a program is linked with them.
3431 @node Dlopened modules
3432 @chapter Dlopened modules
3433 @findex dlopen
3434 @findex dlsym
3435 @findex dlclose
3436 @findex shl_load
3437 @cindex dynamic linking, applications
3438 @cindex dlopening modules
3439 @cindex modules, dynamic
3440 @cindex application-level dynamic linking
3442 It can sometimes be confusing to discuss @dfn{dynamic linking}, because
3443 the term is used to refer to two different concepts:
3445 @enumerate 1
3446 @item
3447 Compiling and linking a program against a shared library, which is
3448 resolved automatically at run time by the dynamic linker.  In this
3449 process, dynamic linking is transparent to the application.
3451 @item
3452 The application calling functions such as @code{dlopen} that load
3453 arbitrary, user-specified modules at runtime.  This type of dynamic
3454 linking is explicitly controlled by the application.
3455 @end enumerate
3457 To mitigate confusion, this manual refers to the second type of dynamic
3458 linking as @dfn{dlopening} a module.
3460 The main benefit to dlopening object modules is the ability to access
3461 compiled object code to extend your program, rather than using an
3462 interpreted language.  In fact, dlopen calls are frequently used in
3463 language interpreters to provide an efficient way to extend the
3464 language.
3466 Libtool provides support for dlopened modules.  However, you should
3467 indicate that your package is willing to use such support, by using the
3468 @code{LT_INIT} option @samp{dlopen} in @file{configure.ac}.  If this
3469 option is not given, libtool will assume no dlopening mechanism is
3470 available, and will try to simulate it.
3472 This chapter discusses how you as a dlopen application developer might
3473 use libtool to generate dlopen-accessible modules.
3475 @menu
3476 * Building modules::            Creating dlopenable objects and libraries.
3477 * Dlpreopening::                Dlopening that works on static platforms.
3478 * Linking with dlopened modules::  Using dlopenable modules in libraries.
3479 * Finding the dlname::          Choosing the right file to @code{dlopen}.
3480 * Dlopen issues::               Unresolved problems that need your attention.
3481 @end menu
3483 @node Building modules
3484 @section Building modules to dlopen
3486 On some operating systems, a program symbol must be specially declared
3487 in order to be dynamically resolved with the @code{dlsym} (or
3488 equivalent) function.  Libtool provides the @option{-export-dynamic} and
3489 @option{-module} link flags (@pxref{Link mode}), for you to make that
3490 declaration.  You need to use these flags if you are linking an
3491 application program that dlopens other modules or a libtool library
3492 that will also be dlopened.
3494 For example, if we wanted to build a shared library, @file{hello},
3495 that would later be dlopened by an application, we would add
3496 @option{-module} to the other link flags:
3498 @example
3499 burger$ @kbd{libtool --mode=link gcc -module -o hello.la foo.lo \
3500                 hello.lo -rpath /usr/local/lib -lm}
3501 burger$
3502 @end example
3504 If symbols from your @emph{executable} are needed to satisfy unresolved
3505 references in a library you want to dlopen you will have to use the flag
3506 @option{-export-dynamic}.  You should use @option{-export-dynamic} while
3507 linking the executable that calls dlopen:
3509 @example
3510 burger$ @kbd{libtool --mode=link gcc -export-dynamic -o helldl main.o}
3511 burger$
3512 @end example
3514 @node Dlpreopening
3515 @section Dlpreopening
3517 Libtool provides special support for dlopening libtool object and
3518 libtool library files, so that their symbols can be resolved
3519 @emph{even on platforms without any @code{dlopen} and @code{dlsym}
3520 functions}.
3522 Consider the following alternative ways of loading code into your
3523 program, in order of increasing ``laziness'':
3525 @enumerate 1
3526 @item
3527 Linking against object files that become part of the program executable,
3528 whether or not they are referenced.  If an object file cannot be found,
3529 then the compile time linker refuses to create the executable.
3531 @item
3532 Declaring a static library to the linker, so that it is searched at link
3533 time to satisfy any undefined references in the above object
3534 files.  If the static library cannot be found, then the compile time
3535 linker refuses to create the executable.
3537 @item
3538 Declaring a shared library to the runtime linker, so that it is searched
3539 at runtime to satisfy any undefined references in the above
3540 files.  If the shared library cannot be found, then the dynamic linker
3541 aborts the program before it runs.
3543 @item
3544 Dlopening a module, so that the application can resolve its own,
3545 dynamically-computed references.  If there is an error opening the
3546 module, or the module is not found, then the application can recover
3547 without crashing.
3548 @end enumerate
3550 Libtool emulates @option{-dlopen} on static platforms by linking objects
3551 into the program at compile time, and creating data structures that
3552 represent the program's symbol table.  In order to use this feature,
3553 you must declare the objects you want your application to dlopen by
3554 using the @option{-dlopen} or @option{-dlpreopen} flags when you link your
3555 program (@pxref{Link mode}).
3557 @deftp {Data Type} {lt_dlsymlist} typedef struct @
3558   @{ @w{const char *@var{name};} @w{void *@var{address};} @} lt_dlsymlist
3559 The @var{name} attribute is a null-terminated character string of the
3560 symbol name, such as @code{"fprintf"}.  The @var{address} attribute is a
3561 generic pointer to the appropriate object, such as @code{&fprintf}.
3562 @end deftp
3564 @deftypevar {const lt_dlsymlist } lt_preloaded_symbols[]
3565 An array of @code{lt_dlsymlist} structures, representing all the preloaded
3566 symbols linked into the program proper.  For each module
3567 @option{-dlpreopen}ed by the Libtool linked program
3568 there is an element with the @var{name} of the module and an @var{address}
3569 of @code{0}, followed by all symbols exported from this file.
3570 For the executable itself the special name @samp{@@PROGRAM@@} is used.
3571 The last element of all has a @var{name} and @var{address} of
3572 @code{0}.
3574 To facilitate inclusion of symbol lists into libraries,
3575 @code{lt_preloaded_symbols} is @samp{#define}d to a suitably unique name
3576 in @file{ltdl.h}.
3578 This variable may not be declared @code{const} on some systems due to
3579 relocation issues.
3580 @end deftypevar
3582 Some compilers may allow identifiers that are not valid in ANSI C, such
3583 as dollar signs.  Libtool only recognizes valid ANSI C symbols (an
3584 initial ASCII letter or underscore, followed by zero or more ASCII
3585 letters, digits, and underscores), so non-ANSI symbols will not appear
3586 in @code{lt_preloaded_symbols}.
3588 @deftypefun int lt_dlpreload (const lt_dlsymlist *@var{preloaded})
3589 Register the list of preloaded modules @var{preloaded}.
3590 If @var{preloaded} is @code{NULL}, then all previously registered
3591 symbol lists, except the list set by @code{lt_dlpreload_default},
3592 are deleted.  Return 0 on success.
3593 @end deftypefun
3595 @deftypefun int lt_dlpreload_default (const lt_dlsymlist *@var{preloaded})
3596 Set the default list of preloaded modules to @var{preloaded}, which
3597 won't be deleted by @code{lt_dlpreload}.  Note that this function does
3598 @emph{not} require libltdl to be initialized using @code{lt_dlinit} and
3599 can be used in the program to register the default preloaded modules.
3600 Instead of calling this function directly, most programs will use the
3601 macro @code{LTDL_SET_PRELOADED_SYMBOLS}.
3603 Return 0 on success.
3604 @end deftypefun
3606 @defmac LTDL_SET_PRELOADED_SYMBOLS
3607 Set the default list of preloaded symbols.
3608 Should be used in your program to initialize libltdl's
3609 list of preloaded modules.
3611 @example
3612 #include <ltdl.h>
3614 int main() @{
3615   /* ... */
3616   LTDL_SET_PRELOADED_SYMBOLS();
3617   /* ... */
3619 @end example
3620 @end defmac
3622 @deftypefn {Function Type} {int} lt_dlpreload_callback_func (lt_dlhandle @var{handle})
3623 Functions of this type can be passed to @code{lt_dlpreload_open},
3624 which in turn will call back into a function thus passed for each
3625 preloaded module that it opens.
3626 @end deftypefn
3628 @deftypefun int lt_dlpreload_open (@w{const char *@var{originator},} @w{lt_dlpreload_callback_func *@var{func})}
3629 Load all of the preloaded modules for @var{originator}.  For every
3630 module opened in this way, call @var{func}.
3632 @noindent
3633 To open all of the modules preloaded into @file{libhell.la}
3634 (presumably from within the @file{libhell.a} initialisation code):
3636 @example
3637 #define preloaded_symbols lt_libhell_LTX_preloaded_symbols
3639 static int hell_preload_callback (lt_dlhandle handle);
3642 hell_init (void)
3644   @dots{}
3645   if (lt_dlpreload (&preloaded_symbols) == 0)
3646     @{
3647       lt_dlpreload_open ("libhell", preload_callback);
3648     @}
3649   @dots{}
3651 @end example
3653 @noindent
3654 Note that to prevent clashes between multiple preloaded modules, the
3655 preloaded symbols are accessed via a mangled symbol name: to get the
3656 symbols preloaded into @samp{libhell}, you must prefix
3657 @samp{preloaded_symbols} with @samp{lt_}; the originator name,
3658 @samp{libhell} in this case; and @samp{_LTX_}.  That is,
3659 @samp{lt_libhell_LTX_preloaded_symbols} here.
3660 @end deftypefun
3663 @node Linking with dlopened modules
3664 @section Linking with dlopened modules
3665 @cindex linking, dlopen
3666 @cindex linking, dlpreopen
3668 When, say, an interpreter application uses dlopened modules to extend
3669 the list of methods it provides, an obvious abstraction for the
3670 maintainers of the interpreter is to have all methods (including the
3671 built in ones supplied with the interpreter) accessed through
3672 dlopen.  For one thing, the dlopening functionality will be tested
3673 even during routine invocations.  For another, only one subsystem has
3674 to be written for getting methods into the interpreter.
3676 The downside of this abstraction is, of course, that environments that
3677 provide only static linkage can't even load the intrinsic interpreter
3678 methods.  Not so!  We can statically link those methods by
3679 @strong{dlpreopening} them.
3681 Unfortunately, since platforms such as AIX and cygwin require
3682 that all library symbols must be resolved at compile time, the
3683 interpreter maintainers will need to provide a library to both its own
3684 dlpreopened modules, and third-party modules loaded by dlopen.  In
3685 itself, that is not so bad, except that the interpreter too must
3686 provide those same symbols otherwise it will be impossible to resolve
3687 all the symbols required by the modules as they are loaded.  Things
3688 are even worse if the code that loads the modules for the interpreter
3689 is itself in a library -- and that is usually the case for any
3690 non-trivial application.  Modern platforms take care of this by
3691 automatically loading all of a module's dependency libraries as the
3692 module is loaded (libltdl can do this even on platforms that can't do
3693 it by themselves).  In the end, this leads to problems with duplicated
3694 symbols and prevents modules from loading, and prevents the
3695 application from compiling when modules are preloaded.
3697 @example
3698 ,-------------.    ,------------------.    ,-----------------.
3699 | Interpreter |---->     Module------------>   Third-party   |
3700 `-------------'    |     Loader       |    |Dlopened Modules |
3701                    |        |         |    `-----------------'
3702                    |,-------v--------.|             |
3703                    ||  Dlpreopened   ||             |
3704                    ||    Modules     ||             |
3705                    |`----------------'|             |
3706                    |        |         |             |
3707                    |,-------v--------.|    ,--------v--------.
3708                    ||Module Interface||    |Module Interface |
3709                    ||    Library     ||    |     Library     |
3710                    |`----------------'|    `-----------------'
3711                    `------------------'
3712 @end example
3714 Libtool has the concept of @dfn{weak library interfaces} to circumvent
3715 this problem.  Recall that the code that dlopens method-provider
3716 modules for the interpreter application resides in a library: All of
3717 the modules and the dlopener library itself should be linked against
3718 the common library that resolves the module symbols at compile time.
3719 To guard against duplicate symbol definitions, and for dlpreopened
3720 modules to work at all in this scenario, the dlopener library must
3721 declare that it provides a weak library interface to the common
3722 symbols in the library it shares with the modules.  That way, when
3723 @command{libtool} links the @strong{Module Loader} library with some
3724 @strong{Dlpreopened Modules} that were in turn linked against the
3725 @strong{Module Interface Library}, it knows that the @strong{Module
3726 Loader} provides an already loaded @strong{Module Interface Library}
3727 to resolve symbols for the @strong{Dlpreopened Modules}, and doesn't
3728 ask the compiler driver to link an identical @strong{Module Interface
3729 Library} dependency library too.
3731 In conjunction with Automake, the @file{Makefile.am} for the
3732 @strong{Module Loader} might look like this:
3734 @example
3735 lib_LTLIBRARIES = libinterface.la libloader.la
3737 libinterface_la_SOURCES = interface.c interface.h
3738 libinterface_la_LDFLAGS = -version-info 3:2:1
3740 libloader_la_SOURCES    = loader.c
3741 libloader_la_LDFLAGS    = -weak libinterface.la \
3742                           -version-info 3:2:1 \
3743                           -dlpreopen ../modules/intrinsics.la
3744 libloader_la_LIBADD     = $(libinterface_la_OBJECTS)
3745 @end example
3747 And the @file{Makefile.am} for the @file{intrinsics.la} module in a
3748 sibling @file{modules} directory might look like this:
3750 @example
3751 AM_CPPFLAGS             = -I$(srcdir)/../libloader
3752 AM_LDFLAGS              = -no-undefined -module -avoid-version \
3753                           -export-dynamic
3755 noinst_LTLIBRARIES      = intrinsics.la
3757 intrinsics_la_LIBADD    = ../libloader/libinterface.la
3759 ../libloader/libinterface.la:
3760         cd ../libloader && $(MAKE) $(AM_MAKEFLAGS) libinterface.la
3761 @end example
3763 @cindex @option{-weak} option
3764 For a more complex example, see the sources of @file{libltdl} in the
3765 Libtool distribution, which is built with the help of the @option{-weak}
3766 option.
3769 @node Finding the dlname
3770 @section Finding the correct name to dlopen
3771 @cindex names of dynamic modules
3772 @cindex dynamic modules, names
3774 After a library has been linked with @option{-module}, it can be dlopened.
3775 Unfortunately, because of the variation in library names,
3776 your package needs to determine the correct file to dlopen.
3778 The most straightforward and flexible implementation is to determine the
3779 name at runtime, by finding the installed @file{.la} file, and searching
3780 it for the following lines:
3782 @example
3783 # The name that we can @code{dlopen}.
3784 dlname='@var{dlname}'
3785 @end example
3787 If @var{dlname} is empty, then the library cannot be dlopened.
3788 Otherwise, it gives the dlname of the library.  So, if the library was
3789 installed as @file{/usr/local/lib/libhello.la}, and the @var{dlname} was
3790 @file{libhello.so.3}, then @file{/usr/local/lib/libhello.so.3} should be
3791 dlopened.
3793 If your program uses this approach, then it should search the
3794 directories listed in the @code{LD_LIBRARY_PATH}@footnote{@code{LIBPATH}
3795 on AIX, and @code{SHLIB_PATH} on HP-UX.} environment variable, as well as
3796 the directory where libraries will eventually be installed.  Searching
3797 this variable (or equivalent) will guarantee that your program can find
3798 its dlopened modules, even before installation, provided you have linked
3799 them using libtool.
3801 @node Dlopen issues
3802 @section Unresolved dlopen issues
3803 @cindex pitfalls with dlopen
3804 @cindex dlopening, pitfalls
3805 @cindex trouble with dlopen
3807 The following problems are not solved by using libtool's dlopen support:
3809 @itemize @bullet
3810 @item
3811 Dlopen functions are generally only available on shared library
3812 platforms.  If you want your package to be portable to static platforms,
3813 you have to use either libltdl (@pxref{Using libltdl}) or develop your
3814 own alternatives to dlopening dynamic code.
3815 Most reasonable solutions involve writing wrapper functions for the
3816 @code{dlopen} family, which do package-specific tricks when dlopening
3817 is unsupported or not available on a given platform.
3819 @item
3820 There are major differences in implementations of the @code{dlopen}
3821 family of functions.  Some platforms do not even use the same function
3822 names (notably HP-UX, with its @code{shl_load} family).
3824 @item
3825 The application developer must write a custom search function
3826 to discover the correct module filename to supply to @code{dlopen}.
3827 @end itemize
3829 @node Using libltdl
3830 @chapter Using libltdl
3831 @findex libltdl
3832 @findex dlopen
3833 @findex dlsym
3834 @findex dlclose
3835 @findex dlerror
3836 @findex shl_load
3837 @cindex dynamic linking, applications
3838 @cindex dlopening modules
3839 @cindex modules, dynamic
3840 @cindex application-level dynamic linking
3842 Libtool provides a small library, called @file{libltdl}, that aims at
3843 hiding the various difficulties of dlopening libraries from programmers.
3844 It consists of a few headers and small C source files that can be
3845 distributed with applications that need dlopening functionality.  On
3846 some platforms, whose dynamic linkers are too limited for a simple
3847 implementation of @file{libltdl} services, it requires GNU DLD, or it
3848 will only emulate dynamic linking with libtool's dlpreopening mechanism.
3850 @noindent
3851 libltdl supports currently the following dynamic linking mechanisms:
3853 @itemize @bullet
3854 @item
3855 @code{dlopen} (POSIX compliant systems, GNU/Linux, etc.)
3856 @item
3857 @code{shl_load} (HP-UX)
3858 @item
3859 @code{LoadLibrary} (Win16 and Win32)
3860 @item
3861 @code{load_add_on} (BeOS)
3862 @item
3863 @code{NSAddImage} or @code{NSLinkModule} (Darwin and Mac OS X)
3864 @item
3865 GNU DLD (emulates dynamic linking for static libraries)
3866 @item
3867 libtool's dlpreopen (@pxref{Dlpreopening})
3868 @end itemize
3870 @noindent
3871 libltdl is licensed under the terms of the GNU Lesser General
3872 Public License, with the following exception:
3874 @quotation
3875 As a special exception to the GNU Lesser General Public License,
3876 if you distribute this file as part of a program or library that
3877 is built using GNU Libtool, you may include it under the same
3878 distribution terms that you use for the rest of that program.
3879 @end quotation
3881 @menu
3882 * Libltdl interface::           How to use libltdl in your programs.
3883 * Modules for libltdl::         Creating modules that can be @code{dlopen}ed.
3884 * Thread Safety in libltdl::    Registering callbacks for multi-thread safety.
3885 * User defined module data::    Associating data with loaded modules.
3886 * Module loaders for libltdl::  Creating user defined module loaders.
3887 * Distributing libltdl::        How to distribute libltdl with your package.
3888 @end menu
3890 @node Libltdl interface
3891 @section How to use libltdl in your programs
3893 @noindent
3894 The libltdl API is similar to the POSIX dlopen interface,
3895 which is very simple but powerful.
3897 @noindent
3898 To use libltdl in your program you have to include the header file @file{ltdl.h}:
3900 @example
3901 #include <ltdl.h>
3902 @end example
3904 @noindent
3905 The early releases of libltdl used some symbols that violated the
3906 POSIX namespace conventions.  These symbols are now deprecated,
3907 and have been replaced by those described here.  If you have code that
3908 relies on the old deprecated symbol names, defining
3909 @samp{LT_NON_POSIX_NAMESPACE} before you include @file{ltdl.h} provides
3910 conversion macros.  Whichever set of symbols you use, the new API is
3911 not binary compatible with the last, so you will need to recompile
3912 your application to use this version of libltdl.
3914 @noindent
3915 Note that libltdl is not well tested in a multithreaded environment,
3916 though the intention is that it should work (@pxref{Thread Safety
3917 in libltdl, , Using libltdl in a multi threaded environment}).  It was
3918 reported that GNU/Linux's glibc 2.0's @code{dlopen} with
3919 @samp{RTLD_LAZY} (that libltdl uses by default) is not thread-safe,
3920 but this problem is supposed to be fixed in glibc 2.1.  On the other
3921 hand, @samp{RTLD_NOW} was reported to introduce problems in
3922 multi-threaded applications on FreeBSD@.  Working around these problems
3923 is left as an exercise for the reader; contributions are certainly
3924 welcome.
3926 @noindent
3927 The following macros are defined by including @file{ltdl.h}:
3929 @defmac LT_PATHSEP_CHAR
3930 @code{LT_PATHSEP_CHAR} is the system-dependent path separator,
3931 that is, @samp{;} on Windows and @samp{:} everywhere else.
3932 @end defmac
3934 @defmac LT_DIRSEP_CHAR
3935 If @code{LT_DIRSEP_CHAR} is defined, it can be used as directory
3936 separator in addition to @samp{/}.  On Windows, this contains
3937 @samp{\}.
3938 @end defmac
3941 @noindent
3942 The following types are defined in @file{ltdl.h}:
3944 @deftp {Type} lt_dlhandle
3945 @code{lt_dlhandle} is a module ``handle''.
3946 Every lt_dlopened module has a handle associated with it.
3947 @end deftp
3949 @deftp {Type} lt_dladvise
3950 @code{lt_dladvise} is used to control optional module loading modes.
3951 If it is not used, the default mode of the underlying system module
3952 loader is used.
3953 @end deftp
3955 @deftp {Type} lt_dlsymlist
3956 @code{lt_dlsymlist} is a symbol list for dlpreopened modules
3957 (@pxref{Dlpreopening}).
3958 @end deftp
3960 @page
3961 @noindent
3962 libltdl provides the following functions:
3964 @deftypefun int lt_dlinit (void)
3965 Initialize libltdl.
3966 This function must be called before using libltdl
3967 and may be called several times.
3968 Return 0 on success, otherwise the number of errors.
3969 @end deftypefun
3971 @deftypefun int lt_dlexit (void)
3972 Shut down libltdl and close all modules.
3973 This function will only then shut down libltdl when it was called as
3974 many times as @code{lt_dlinit} has been successfully called.
3975 Return 0 on success, otherwise the number of errors.
3976 @end deftypefun
3978 @deftypefun lt_dlhandle lt_dlopen (const char *@var{filename})
3979 Open the module with the file name @var{filename} and return a
3980 handle for it.  @code{lt_dlopen} is able to open libtool dynamic
3981 modules, preloaded static modules, the program itself and
3982 native dynamic modules@footnote{Some platforms, notably Mac OS X,
3983 differentiate between a runtime library that cannot be opened by
3984 @code{lt_dlopen} and a dynamic module that can.  For maximum
3985 portability you should try to ensure that you only pass
3986 @code{lt_dlopen} objects that have been compiled with libtool's
3987 @option{-module} flag.}.
3989 Unresolved symbols in the module are resolved using its dependency
3990 libraries and previously dlopened modules.  If the executable using
3991 this module was linked with the @option{-export-dynamic} flag, then the
3992 global symbols in the executable will also be used to resolve
3993 references in the module.
3995 If @var{filename} is @code{NULL} and the program was linked with
3996 @option{-export-dynamic} or @option{-dlopen self}, @code{lt_dlopen} will
3997 return a handle for the program itself, which can be used to access its
3998 symbols.
4000 If libltdl cannot find the library and the file name @var{filename} does
4001 not have a directory component it will additionally look in the
4002 following search paths for the module (in the following order):
4004 @enumerate 1
4005 @item user-defined search path:
4006 This search path can be changed by the program using the
4007 functions @code{lt_dlsetsearchpath}, @code{lt_dladdsearchdir} and
4008 @code{lt_dlinsertsearchdir}.
4010 @item libltdl's search path:
4011 This search path is the value of the environment variable
4012 @env{LTDL_LIBRARY_PATH}.
4014 @item system library search path:
4015 The system dependent library search path
4016 (e.g.@: on GNU/Linux it is @env{LD_LIBRARY_PATH}).
4017 @end enumerate
4019 Each search path must be a list of absolute directories separated by
4020 @code{LT_PATHSEP_CHAR}, for example, @code{"/usr/lib/mypkg:/lib/foo"}.
4021 The directory names may not contain the path separator.
4023 If the same module is loaded several times, the same handle is returned.
4024 If @code{lt_dlopen} fails for any reason, it returns @code{NULL}.
4025 @end deftypefun
4027 @deftypefun lt_dlhandle lt_dlopenext (const char *@var{filename})
4028 The same as @code{lt_dlopen}, except that it tries to append
4029 different file name extensions to the file name.
4030 If the file with the file name @var{filename} cannot be found
4031 libltdl tries to append the following extensions:
4033 @enumerate 1
4034 @item the libtool archive extension @file{.la}
4035 @item the extension used for native dynamically loadable modules on the host platform, e.g., @file{.so}, @file{.sl}, etc.
4036 @end enumerate
4038 This lookup strategy was designed to allow programs that don't
4039 have knowledge about native dynamic libraries naming conventions
4040 to be able to @code{dlopen} such libraries as well as libtool modules
4041 transparently.
4042 @end deftypefun
4044 @deftypefun lt_dlhandle lt_dlopenadvise (const char *@var{filename}, @w{lt_dladvise @var{advise}})
4045 The same as @code{lt_dlopen}, except that it also requires an additional
4046 argument that may contain additional hints to the underlying system
4047 module loader.  The @var{advise} parameter is opaque and can only be
4048 accessed with the functions documented below.
4050 Note that this function does not change the content of @var{advise}, so
4051 unlike the other calls in this API takes a direct @code{lt_dladvise}
4052 type, and not a pointer to the same.
4053 @end deftypefun
4055 @deftypefun int lt_dladvise_init (lt_dladvise *@var{advise})
4056 The @var{advise} parameter can be used to pass hints to the module
4057 loader when using @code{lt_dlopenadvise} to perform the loading.
4058 The @var{advise} parameter needs to be initialised by this function
4059 before it can be used.  Any memory used by @var{advise} needs to be
4060 recycled with @code{lt_dladvise_destroy} when it is no longer needed.
4062 On failure, @code{lt_dladvise_init} returns non-zero and sets an error
4063 message that can be retrieved with @code{lt_dlerror}.
4064 @end deftypefun
4066 @deftypefun int lt_dladvise_destroy (lt_dladvise *@var{advise})
4067 Recycle the memory used by @var{advise}.  For an example, see the
4068 documentation for @code{lt_dladvise_ext}.
4070 On failure, @code{lt_dladvise_destroy} returns non-zero and sets an error
4071 message that can be retrieved with @code{lt_dlerror}.
4072 @end deftypefun
4074 @deftypefun int lt_dladvise_ext (lt_dladvise *@var{advise})
4075 Set the @code{ext} hint on @var{advise}.  Passing an @var{advise}
4076 parameter to @code{lt_dlopenadvise} with this hint set causes it to
4077 try to append different file name extensions like @code{lt_dlopenext}.
4079 The following example is equivalent to calling
4080 @code{lt_dlopenext (filename)}:
4082 @example
4083 lt_dlhandle
4084 my_dlopenext (const char *filename)
4086   lt_dlhandle handle = 0;
4087   lt_dladvise advise;
4089   if (!lt_dladvise_init (&advise) && !lt_dladvise_ext (&advise))
4090     handle = lt_dlopenadvise (filename, advise);
4092   lt_dladvise_destroy (&advise);
4094   return handle;
4096 @end example
4098 On failure, @code{lt_dladvise_ext} returns non-zero and sets an error
4099 message that can be retrieved with @code{lt_dlerror}.
4100 @end deftypefun
4102 @deftypefun int lt_dladvise_global (lt_dladvise *@var{advise})
4103 Set the @code{symglobal} hint on @var{advise}.  Passing an @var{advise}
4104 parameter to @code{lt_dlopenadvise} with this hint set causes it to try
4105 to make the loaded module's symbols globally available for resolving
4106 unresolved symbols in subsequently loaded modules.
4108 If neither the @code{symglobal} nor the @code{symlocal} hints are set,
4109 or if a module is loaded without using the @code{lt_dlopenadvise} call
4110 in any case, then the visibility of the module's symbols will be as per
4111 the default for the underlying module loader and OS.  Even if a
4112 suitable hint is passed, not all loaders are able to act upon it in
4113 which case @code{lt_dlgetinfo} will reveal whether the hint was actually
4114 followed.
4116 On failure, @code{lt_dladvise_global} returns non-zero and sets an error
4117 message that can be retrieved with @code{lt_dlerror}.
4118 @end deftypefun
4120 @deftypefun int lt_dladvise_local (lt_dladvise *@var{advise})
4121 Set the @code{symlocal} hint on @var{advise}.  Passing an @var{advise}
4122 parameter to @code{lt_dlopenadvise} with this hint set causes it to try
4123 to keep the loaded module's symbols hidden so that they are not
4124 visible to subsequently loaded modules.
4126 If neither the @code{symglobal} nor the @code{symlocal} hints are set,
4127 or if a module is loaded without using the @code{lt_dlopenadvise} call
4128 in any case, then the visibility of the module's symbols will be as per
4129 the default for the underlying module loader and OS.  Even if a
4130 suitable hint is passed, not all loaders are able to act upon it in
4131 which case @code{lt_dlgetinfo} will reveal whether the hint was actually
4132 followed.
4134 On failure, @code{lt_dladvise_local} returns non-zero and sets an error
4135 message that can be retrieved with @code{lt_dlerror}.
4136 @end deftypefun
4138 @deftypefun int lt_dladvise_resident (lt_dladvise *@var{advise})
4139 Set the @code{resident} hint on @var{advise}.  Passing an @var{advise}
4140 parameter to @code{lt_dlopenadvise} with this hint set causes it to try
4141 to make the loaded module resident in memory, so that it cannot be
4142 unloaded with a later call to @code{lt_dlclose}.
4144 On failure, @code{lt_dladvise_resident} returns non-zero and sets an error
4145 message that can be retrieved with @code{lt_dlerror}.
4146 @end deftypefun
4148 @deftypefun int lt_dladvise_preload (lt_dladvise *@var{advise})
4149 Set the @code{preload} hint on @var{advise}.  Passing an @var{advise}
4150 parameter to @code{lt_dlopenadvise} with this hint set causes it to
4151 load only preloaded modules, so that if a suitable preloaded module is
4152 not found, @code{lt_dlopenadvise} will return @code{NULL}.
4153 @end deftypefun
4155 @deftypefun int lt_dlclose (lt_dlhandle @var{handle})
4156 Decrement the reference count on the module @var{handle}.
4157 If it drops to zero and no other module depends on this module,
4158 then the module is unloaded.
4159 Return 0 on success.
4160 @end deftypefun
4162 @deftypefun {void *} lt_dlsym (lt_dlhandle @var{handle}, const char *@var{name})
4163 Return the address in the module @var{handle}, where the symbol given
4164 by the null-terminated string @var{name} is loaded.
4165 If the symbol cannot be found, @code{NULL} is returned.
4166 @end deftypefun
4168 @deftypefun {const char *} lt_dlerror (void)
4169 Return a human readable string describing the most
4170 recent error that occurred from any of libltdl's functions.
4171 Return @code{NULL} if no errors have occurred since initialization
4172 or since it was last called.
4173 @end deftypefun
4175 @deftypefun int lt_dladdsearchdir (const char *@var{search_dir})
4176 Append the search directory @var{search_dir} to the current user-defined
4177 library search path.  Return 0 on success.
4178 @end deftypefun
4180 @deftypefun int lt_dlinsertsearchdir (@w{const char *@var{before}}, @w{const char *@var{search_dir}})
4181 Insert the search directory @var{search_dir} into the user-defined library
4182 search path, immediately before the element starting at address
4183 @var{before}.  If @var{before} is @samp{NULL}, then @var{search_dir} is
4184 appending as if @code{lt_dladdsearchdir} had been called.  Return 0 on success.
4185 @end deftypefun
4187 @deftypefun int lt_dlsetsearchpath (const char *@var{search_path})
4188 Replace the current user-defined library search path with
4189 @var{search_path}, which must be a list of absolute directories separated
4190 by @code{LT_PATHSEP_CHAR}.  Return 0 on success.
4191 @end deftypefun
4193 @deftypefun {const char *} lt_dlgetsearchpath (void)
4194 Return the current user-defined library search path.
4195 @end deftypefun
4197 @deftypefun int lt_dlforeachfile (@w{const char *@var{search_path}}, @w{int (*@var{func}) (const char *@var{filename}, void * @var{data})}, @w{void * @var{data}})
4198 In some applications you may not want to load individual modules with
4199 known names, but rather find all of the modules in a set of
4200 directories and load them all during initialisation.  With this function
4201 you can have libltdl scan the @code{LT_PATHSEP_CHAR}-delimited directory list
4202 in @var{search_path} for candidates, and pass them, along with
4203 @var{data} to your own callback function, @var{func}.  If @var{search_path} is
4204 @samp{NULL}, then search all of the standard locations that
4205 @code{lt_dlopen} would examine.  This function will continue to make
4206 calls to @var{func} for each file that it discovers in @var{search_path}
4207 until one of these calls returns non-zero, or until the files are
4208 exhausted.  @samp{lt_dlforeachfile} returns the value returned by the last
4209 call made to @var{func}.
4211 For example you could define @var{func} to build an ordered
4212 @dfn{argv}-like vector of files using @var{data} to hold the address of
4213 the start of the vector.
4214 @end deftypefun
4216 @deftypefun int lt_dlmakeresident (lt_dlhandle @var{handle})
4217 Mark a module so that it cannot be @samp{lt_dlclose}d.  This can be
4218 useful if a module implements some core functionality in your project
4219 that would cause your code to crash if removed.  Return 0 on success.
4221 If you use @samp{lt_dlopen (NULL)} to get a @var{handle} for the running
4222 binary, that handle will always be marked as resident, and consequently
4223 cannot be successfully @samp{lt_dlclose}d.
4224 @end deftypefun
4226 @deftypefun int lt_dlisresident (lt_dlhandle @var{handle})
4227 Check whether a particular module has been marked as resident, returning 1
4228 if it has or 0 otherwise.  If there is an error while executing this
4229 function, return -1 and set an error message for retrieval with
4230 @code{lt_dlerror}.
4231 @end deftypefun
4233 @node Modules for libltdl
4234 @section Creating modules that can be @code{dlopen}ed
4236 Libtool modules are created like normal libtool libraries with a few
4237 exceptions:
4239 You have to link the module with libtool's @option{-module} switch,
4240 and you should link any program that is intended to dlopen the module with
4241 @option{-dlopen @var{modulename.la}} where possible, so that libtool can
4242 dlpreopen the module on platforms that do not support dlopening.  If
4243 the module depends on any other libraries, make sure you specify them
4244 either when you link the module or when you link programs that dlopen it.
4245 If you want to disable versioning (@pxref{Versioning}) for a specific module
4246 you should link it with the @option{-avoid-version} switch.
4247 Note that libtool modules don't need to have a "lib" prefix.
4248 However, Automake 1.4 or higher is required to build such modules.
4250 Usually a set of modules provide the same interface, i.e.@: exports the same
4251 symbols, so that a program can dlopen them without having to know more
4252 about their internals: In order to avoid symbol conflicts all exported
4253 symbols must be prefixed with "modulename_LTX_" (@var{modulename} is
4254 the name of the module).  Internal symbols must be named in such a way
4255 that they won't conflict with other modules, for example, by prefixing
4256 them with "_modulename_".  Although some platforms support having the
4257 same symbols defined more than once it is generally not portable and
4258 it makes it impossible to dlpreopen such modules.
4260 libltdl will automatically cut the prefix off to get the real name of
4261 the symbol.  Additionally, it supports modules that do not use a
4262 prefix so that you can also dlopen non-libtool modules.
4264 @file{foo1.c} gives an example of a portable libtool module.
4265 Exported symbols are prefixed with "foo1_LTX_", internal symbols
4266 with "_foo1_".  Aliases are defined at the beginning so that the code
4267 is more readable.
4269 @example
4270 /* aliases for the exported symbols */
4271 #define foo  foo1_LTX_foo
4272 #define bar  foo1_LTX_bar
4274 /* a global variable definition */
4275 int bar = 1;
4277 /* a private function */
4278 int _foo1_helper() @{
4279   return bar;
4282 /* an exported function */
4283 int foo() @{
4284   return _foo1_helper();
4286 @end example
4288 @noindent
4289 The @file{Makefile.am} contains the necessary rules to build the
4290 module @file{foo1.la}:
4292 @example
4294 lib_LTLIBRARIES = foo1.la
4296 foo1_la_SOURCES = foo1.c
4297 foo1_la_LDFLAGS = -module
4299 @end example
4302 @node Thread Safety in libltdl
4303 @section Using libltdl in a multi threaded environment
4305 Libltdl provides a wrapper around whatever dynamic run-time object
4306 loading mechanisms are provided by the host system, many of which are
4307 themselves not thread safe.  Consequently libltdl cannot itself be
4308 consistently thread safe.
4310 If you wish to use libltdl in a multithreaded environment, then you
4311 must mutex lock around libltdl calls, since they may in turn be calling
4312 non-thread-safe system calls on some target hosts.
4314 Some old releases of libtool provided a mutex locking API that
4315 was unusable with POSIX threads, so callers were forced to lock around
4316 all libltdl API calls anyway.  That mutex locking API was
4317 next to useless, and is not present in current releases.
4319 Some future release of libtool may provide a new POSIX thread
4320 compliant mutex locking API.
4322 @node User defined module data
4323 @section Data associated with loaded modules
4325 Some of the internal information about each loaded module that is
4326 maintained by libltdl is available to the user, in the form of this
4327 structure:
4329 @deftypefn {Type} {struct} lt_dlinfo @{ @w{char *@var{filename};} @
4330   @w{char *@var{name};} @w{int @var{ref_count};} @
4331   @w{int @var{is_resident};} @w{int @var{is_symglobal};} @
4332   @w{int @var{is_symlocal};}@}
4333 @code{lt_dlinfo} is used to store information about a module.
4334 The @var{filename} attribute is a null-terminated character string of
4335 the real module file name.  If the module is a libtool module then
4336 @var{name} is its module name (e.g.@: @code{"libfoo"} for
4337 @code{"dir/libfoo.la"}), otherwise it is set to @code{NULL}.  The
4338 @var{ref_count} attribute is a reference counter that describes how
4339 often the same module is currently loaded. The remaining fields can
4340 be compared to any hints that were passed to @code{lt_dlopenadvise}
4341 to determine whether the underlying loader was able to follow them.
4342 @end deftypefn
4344 The following function will return a pointer to libltdl's internal copy
4345 of this structure for the given @var{handle}:
4347 @deftypefun {const lt_dlinfo *} lt_dlgetinfo (@w{lt_dlhandle @var{handle}})
4348 Return a pointer to a struct that contains some information about
4349 the module @var{handle}.  The contents of the struct must not be modified.
4350 Return @code{NULL} on failure.
4351 @end deftypefun
4353 Furthermore, to save you from having to keep a list of the
4354 handles of all the modules you have loaded, these functions allow you to
4355 iterate over libltdl's list of loaded modules:
4357 @deftp {Type} lt_dlinterface_id
4358 The opaque type used to hold the module interface details for each
4359 registered libltdl client.
4360 @end deftp
4362 @deftypefn {Type} int lt_dlhandle_interface (@w{lt_dlhandle @var{handle},} @
4363   @w{const char *@var{id_string}})
4364 Functions of this type are called to check that a handle conforms to a
4365 library's expected module interface when iterating over the global
4366 handle list.  You should be careful to write a callback function of
4367 this type that can correctly identify modules that belong to this
4368 client, both to prevent other clients from accidentally finding your
4369 loaded modules with the iterator functions below, and vice versa.  The
4370 best way to do this is to check that module @var{handle} conforms
4371 to the interface specification of your loader using @code{lt_dlsym}.
4373 The callback may be given @strong{every} module loaded by all the
4374 libltdl module clients in the current address space, including any
4375 modules loaded by other libraries such as libltdl itself, and should
4376 return non-zero if that module does not fulfill the interface
4377 requirements of your loader.
4379 @example
4381 my_interface_cb (lt_dlhandle handle, const char *id_string)
4383   char *(*module_id) (void) = NULL;
4385   /* @r{A valid my_module must provide all of these symbols.}  */
4386   if (!((module_id = (char*(*)(void)) lt_dlsym ("module_version"))
4387         && lt_dlsym ("my_module_entrypoint")))
4388       return 1;
4390   if (strcmp (id_string, module_id()) != 0)
4391       return 1;
4393   return 0;
4395 @end example
4396 @end deftypefn
4398 @deftypefun lt_dlinterface_id lt_dlinterface_register @
4399   (@w{const char *@var{id_string}}, @w{lt_dlhandle_interface *@var{iface}})
4400 Use this function to register your interface validator with libltdl,
4401 and in return obtain a unique key to store and retrieve per-module data.
4402 You supply an @var{id_string} and @var{iface} so that the resulting
4403 @code{lt_dlinterface_id} can be used to filter the module handles
4404 returned by the iteration functions below.  If @var{iface} is @code{NULL},
4405 all modules will be matched.
4406 @end deftypefun
4408 @deftypefun void lt_dlinterface_free (@w{lt_dlinterface_id @var{iface}})
4409 Release the data associated with @var{iface}.
4410 @end deftypefun
4412 @deftypefun int lt_dlhandle_map (@w{lt_dlinterface_id @var{iface}}, @
4413   @w{int (*@var{func}) (lt_dlhandle @var{handle}, void * @var{data})}, @
4414   @w{void * @var{data}})
4415 For each module that matches @var{iface}, call the function
4416 @var{func}.  When writing the @var{func} callback function, the
4417 argument @var{handle} is the handle of a loaded module, and
4418 @var{data} is the last argument passed to @code{lt_dlhandle_map}. As
4419 soon as @var{func} returns a non-zero value for one of the handles,
4420 @code{lt_dlhandle_map} will stop calling @var{func} and immediately
4421 return that non-zero value.  Otherwise 0 is eventually returned when
4422 @var{func} has been successfully called for all matching modules.
4423 @end deftypefun
4425 @deftypefun lt_dlhandle lt_dlhandle_iterate (@w{lt_dlinterface_id @
4426   @var{iface}}, @w{lt_dlhandle @var{place}})
4427 Iterate over the module handles loaded by @var{iface}, returning the
4428 first matching handle in the list if @var{place} is @code{NULL}, and
4429 the next one on subsequent calls.  If @var{place} is the last element
4430 in the list of eligible modules, this function returns @code{NULL}.
4432 @example
4433 lt_dlhandle handle = 0;
4434 lt_dlinterface_id iface = my_interface_id;
4436 while ((handle = lt_dlhandle_iterate (iface, handle)))
4437   @{
4438     @dots{}
4439   @}
4440 @end example
4441 @end deftypefun
4443 @deftypefun lt_dlhandle lt_dlhandle_fetch (@w{lt_dlinterface_id @var{iface}}, @w{const char *@var{module_name}})
4444 Search through the module handles loaded by @var{iface} for a module named
4445 @var{module_name}, returning its handle if found or else @code{NULL}
4446 if no such named module has been loaded by @var{iface}.
4447 @end deftypefun
4449 However, you might still need to maintain your own list of loaded
4450 module handles (in parallel with the list maintained inside libltdl)
4451 if there were any other data that your application wanted to associate
4452 with each open module.  Instead, you can use the following API
4453 calls to do that for you.  You must first obtain a unique interface id
4454 from libltdl as described above, and subsequently always use it to
4455 retrieve the data you stored earlier.  This allows different libraries
4456 to each store their own data against loaded modules, without
4457 interfering with one another.
4459 @deftypefun {void *} lt_dlcaller_set_data (@w{lt_dlinterface_id @var{key}}, @w{lt_dlhandle @var{handle}}, @w{void * @var{data}})
4460 Set @var{data} as the set of data uniquely associated with @var{key} and
4461 @var{handle} for later retrieval.  This function returns the @var{data}
4462 previously associated with @var{key} and @var{handle} if any.  A result of
4463 0, may indicate that a diagnostic for the last error (if any) is available
4464 from @code{lt_dlerror()}.
4466 For example, to correctly remove some associated data:
4468 @example
4469 void *stale = lt_dlcaller_set_data (key, handle, 0);
4470 if (stale != NULL)
4471   @{
4472     free (stale);
4473   @}
4474 else
4475   @{
4476     char *error_msg = lt_dlerror ();
4478     if (error_msg != NULL)
4479       @{
4480         my_error_handler (error_msg);
4481         return STATUS_FAILED;
4482       @}
4483   @}
4484 @end example
4485 @end deftypefun
4487 @deftypefun {void *} lt_dlcaller_get_data (@w{lt_dlinterface_id @var{key}}, @w{lt_dlhandle @var{handle}})
4488 Return the address of the data associated with @var{key} and
4489 @var{handle}, or else @code{NULL} if there is none.
4490 @end deftypefun
4492 Old versions of libltdl also provided a simpler, but similar, API
4493 based around @code{lt_dlcaller_id}.  Unfortunately, it had no
4494 provision for detecting whether a module belonged to a particular
4495 interface as libltdl didn't support multiple loaders in the same
4496 address space at that time.  Those APIs are no longer supported
4497 as there would be no way to stop clients of the old APIs from
4498 seeing (and accidentally altering) modules loaded by other libraries.
4501 @node Module loaders for libltdl
4502 @section How to create and register new module loaders
4504 Sometimes libltdl's many ways of gaining access to modules are not
4505 sufficient for the purposes of a project.  You can write your own
4506 loader, and register it with libltdl so that @code{lt_dlopen} will be
4507 able to use it.
4509 Writing a loader involves writing at least three functions that can be
4510 called by @code{lt_dlopen}, @code{lt_dlsym} and @code{lt_dlclose}.
4511 Optionally, you can provide a finalisation function to perform any
4512 cleanup operations when @code{lt_dlexit} executes, and a symbol prefix
4513 string that will be prepended to any symbols passed to @code{lt_dlsym}.
4514 These functions must match the function pointer types below, after
4515 which they can be allocated to an instance of @code{lt_user_dlloader}
4516 and registered.
4518 Registering the loader requires that you choose a name for it, so that it
4519 can be recognised by @code{lt_dlloader_find} and removed with
4520 @code{lt_dlloader_remove}.  The name you choose must be unique, and not
4521 already in use by libltdl's builtin loaders:
4523 @table @asis
4524 @item "dlopen"
4525 The system dynamic library loader, if one exists.
4526 @item "dld"
4527 The GNU dld loader, if @file{libdld} was installed when libltdl was
4528 built.
4529 @item "dlpreload"
4530 The loader for @code{lt_dlopen}ing of preloaded static modules.
4531 @end table
4533 The prefix "dl" is reserved for loaders supplied with future versions of
4534 libltdl, so you should not use that for your own loader names.
4536 @noindent
4537 The following types are defined in @file{ltdl.h}:
4539 @deftp {Type} lt_module
4540 @code{lt_module} is a dlloader dependent module.
4541 The dynamic module loader extensions communicate using these low
4542 level types.
4543 @end deftp
4545 @deftp {Type} lt_dlloader
4546 @code{lt_dlloader} is a handle for module loader types.
4547 @end deftp
4549 @deftp {Type} lt_user_data
4550 @code{lt_user_data} is used for specifying loader instance data.
4551 @end deftp
4553 @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};} @}
4554 If you want to define a new way to open dynamic modules, and have the
4555 @code{lt_dlopen} API use it, you need to instantiate one of these
4556 structures and pass it to @code{lt_dlloader_add}.  You can pass whatever
4557 you like in the @var{dlloader_data} field, and it will be passed back as
4558 the value of the first parameter to each of the functions specified in
4559 the function pointer fields.
4560 @end deftypefn
4562 @deftypefn {Type} lt_module lt_module_open (@w{const char *@var{filename}})
4563 The type of the loader function for an @code{lt_dlloader} module
4564 loader.  The value set in the dlloader_data field of the @code{struct
4565 lt_user_dlloader} structure will be passed into this function in the
4566 @var{loader_data} parameter.  Implementation of such a function should
4567 attempt to load the named module, and return an @code{lt_module}
4568 suitable for passing in to the associated @code{lt_module_close} and
4569 @code{lt_sym_find} function pointers.  If the function fails it should
4570 return @code{NULL}, and set the error message with @code{lt_dlseterror}.
4571 @end deftypefn
4573 @deftypefn {Type} int lt_module_close (@w{lt_user_data @var{loader_data},} @w{lt_module @var{module}})
4574 The type of the unloader function for a user defined module loader.
4575 Implementation of such a function should attempt to release
4576 any resources tied up by the @var{module} module, and then unload it
4577 from memory.  If the function fails for some reason, set the error
4578 message with @code{lt_dlseterror} and return non-zero.
4579 @end deftypefn
4581 @deftypefn {Type} {void *} lt_find_sym (@w{lt_module @var{module},} @w{const char *@var{symbol}})
4582 The type of the symbol lookup function for a user defined module loader.
4583 Implementation of such a function should return the address of the named
4584 @var{symbol} in the module @var{module}, or else set the error message
4585 with @code{lt_dlseterror} and return @code{NULL} if lookup fails.
4586 @end deftypefn
4588 @deftypefn {Type} int lt_dlloader_exit (@w{lt_user_data @var{loader_data}})
4589 The type of the finalisation function for a user defined module loader.
4590 Implementation of such a function should free any resources associated
4591 with the loader, including any user specified data in the
4592 @code{dlloader_data} field of the @code{lt_user_dlloader}.  If non-@code{NULL},
4593 the function will be called by @code{lt_dlexit}, and
4594 @code{lt_dlloader_remove}.
4595 @end deftypefn
4597 For example:
4599 @example
4601 register_myloader (void)
4603   lt_user_dlloader dlloader;
4605   /* User modules are responsible for their own initialisation. */
4606   if (myloader_init () != 0)
4607     return MYLOADER_INIT_ERROR;
4609   dlloader.sym_prefix    = NULL;
4610   dlloader.module_open   = myloader_open;
4611   dlloader.module_close  = myloader_close;
4612   dlloader.find_sym      = myloader_find_sym;
4613   dlloader.dlloader_exit = myloader_exit;
4614   dlloader.dlloader_data = (lt_user_data)myloader_function;
4616   /* Add my loader as the default module loader. */
4617   if (lt_dlloader_add (lt_dlloader_next (NULL), &dlloader,
4618                        "myloader") != 0)
4619     return ERROR;
4621   return OK;
4623 @end example
4625 Note that if there is any initialisation required for the loader,
4626 it must be performed manually before the loader is registered --
4627 libltdl doesn't handle user loader initialisation.
4629 Finalisation @emph{is} handled by libltdl however, and it is important
4630 to ensure the @code{dlloader_exit} callback releases any resources claimed
4631 during the initialisation phase.
4633 @page
4634 @noindent
4635 libltdl provides the following functions for writing your own module
4636 loaders:
4638 @deftypefun int lt_dlloader_add (@w{lt_dlloader *@var{place},} @
4639   @w{lt_user_dlloader *@var{dlloader},} @w{const char *@var{loader_name}})
4640 Add a new module loader to the list of all loaders, either as the
4641 last loader (if @var{place} is @code{NULL}), else immediately before the
4642 loader passed as @var{place}.  @var{loader_name} will be returned by
4643 @code{lt_dlloader_name} if it is subsequently passed a newly
4644 registered loader.  These @var{loader_name}s must be unique, or
4645 @code{lt_dlloader_remove} and @code{lt_dlloader_find} cannot
4646 work.  Returns 0 for success.
4648 @example
4649 /* Make myloader be the last one. */
4650 if (lt_dlloader_add (NULL, myloader) != 0)
4651   perror (lt_dlerror ());
4652 @end example
4653 @end deftypefun
4655 @deftypefun int lt_dlloader_remove (@w{const char *@var{loader_name}})
4656 Remove the loader identified by the unique name, @var{loader_name}.
4657 Before this can succeed, all modules opened by the named loader must
4658 have been closed.  Returns 0 for success, otherwise an error message can
4659 be obtained from @code{lt_dlerror}.
4661 @example
4662 /* Remove myloader. */
4663 if (lt_dlloader_remove ("myloader") != 0)
4664   perror (lt_dlerror ());
4665 @end example
4666 @end deftypefun
4668 @deftypefun {lt_dlloader *} lt_dlloader_next (@w{lt_dlloader *@var{place}})
4669 Iterate over the module loaders, returning the first loader if @var{place} is
4670 @code{NULL}, and the next one on subsequent calls.  The handle is for use with
4671 @code{lt_dlloader_add}.
4673 @example
4674 /* Make myloader be the first one. */
4675 if (lt_dlloader_add (lt_dlloader_next (NULL), myloader) != 0)
4676   return ERROR;
4677 @end example
4678 @end deftypefun
4680 @deftypefun {lt_dlloader *} lt_dlloader_find (@w{const char *@var{loader_name}})
4681 Return the first loader with a matching @var{loader_name} identifier, or else
4682 @code{NULL}, if the identifier is not found.
4684 The identifiers that may be used by libltdl itself, if the host
4685 architecture supports them are @dfn{dlopen}@footnote{This is used for
4686 the host dependent module loading API -- @code{shl_load} and
4687 @code{LoadLibrary} for example}, @dfn{dld} and @dfn{dlpreload}.
4689 @example
4690 /* Add a user loader as the next module loader to be tried if
4691    the standard dlopen loader were to fail when lt_dlopening. */
4692 if (lt_dlloader_add (lt_dlloader_find ("dlopen"), myloader) != 0)
4693   return ERROR;
4694 @end example
4695 @end deftypefun
4697 @deftypefun {const char *} lt_dlloader_name (@w{lt_dlloader *@var{place}})
4698 Return the identifying name of @var{place}, as obtained from
4699 @code{lt_dlloader_next} or @code{lt_dlloader_find}.  If this function fails,
4700 it will return @code{NULL} and set an error for retrieval with
4701 @code{lt_dlerror}.
4702 @end deftypefun
4704 @deftypefun {lt_user_data *} lt_dlloader_data (@w{lt_dlloader *@var{place}})
4705 Return the address of the @code{dlloader_data} of @var{place}, as
4706 obtained from @code{lt_dlloader_next} or @code{lt_dlloader_find}.  If
4707 this function fails, it will return @code{NULL} and set an error for
4708 retrieval with @code{lt_dlerror}.
4709 @end deftypefun
4711 @subsection Error handling within user module loaders
4713 @deftypefun int lt_dladderror (@w{const char *@var{diagnostic}})
4714 This function allows you to integrate your own error messages into
4715 @code{lt_dlerror}.  Pass in a suitable diagnostic message for return by
4716 @code{lt_dlerror}, and an error identifier for use with
4717 @code{lt_dlseterror} is returned.
4719 If the allocation of an identifier fails, this function returns -1.
4721 @example
4722 int myerror = lt_dladderror ("doh!");
4723 if (myerror < 0)
4724   perror (lt_dlerror ());
4725 @end example
4726 @end deftypefun
4728 @deftypefun int lt_dlseterror (@w{int @var{errorcode}})
4729 When writing your own module loaders, you should use this function to
4730 raise errors so that they are propagated through the @code{lt_dlerror}
4731 interface.  All of the standard errors used by libltdl are declared in
4732 @file{ltdl.h}, or you can add more of your own with
4733 @code{lt_dladderror}.  This function returns 0 on success.
4735 @example
4736 if (lt_dlseterror (LTDL_ERROR_NO_MEMORY) != 0)
4737   perror (lt_dlerror ());
4738 @end example
4739 @end deftypefun
4741 @node Distributing libltdl
4742 @section How to distribute libltdl with your package
4744 Even though libltdl is installed together with libtool, you may wish
4745 to include libltdl in the distribution of your package, for the
4746 convenience of users of your package that don't have libtool or
4747 libltdl installed, or if you are using features of a very new version
4748 of libltdl that you don't expect your users to have yet.  In such
4749 cases, you must decide what flavor of libltdl you want to use: a
4750 convenience library or an installable libtool library.
4752 The most simplistic way to add @code{libltdl} to your package is to
4753 copy all the @file{libltdl} source files to a subdirectory within
4754 your package and to build and link them along with the rest of your
4755 sources.  To help you do this, the m4 macros for Autoconf are
4756 available in @file{ltdl.m4}.  You must ensure that they are available
4757 in @file{aclocal.m4} before you run Autoconf@footnote{@c
4759 We used to recommend adding the contents of @file{ltdl.m4} to
4760 @file{acinclude.m4}, but with @command{aclocal} from a modern
4761 Automake (1.8 or newer) and this release of libltdl that is not only
4762 unnecessary but makes it easy to forget to upgrade @file{acinclude.m4}
4763 if you move to a different release of libltdl.
4765 }.  Having made the macros available, you must add a call to the
4766 @samp{LTDL_INIT} macro (after the call to @samp{LT_INIT})
4767 to your package's @file{configure.ac} to
4768 perform the configure time checks required to build the library
4769 correctly.  Unfortunately, this method has problems if you then try to
4770 link the package binaries with an installed libltdl, or a library that
4771 depends on libltdl, because of the duplicate symbol definitions.  For
4772 example, ultimately linking against two different versions of libltdl,
4773 or against both a local convenience library and an installed libltdl
4774 is bad.  Ensuring that only one copy of the libltdl sources are linked
4775 into any program is left as an exercise for the reader.
4777 @defmac LT_CONFIG_LTDL_DIR (@var{directory})
4778 Declare @var{directory} to be the location of the @code{libltdl}
4779 source files, for @command{libtoolize --ltdl} to place
4780 them. @xref{Invoking libtoolize}, for more details.  Provided that you
4781 add an appropriate @code{LT_CONFIG_LTDL_DIR} call in your
4782 @file{configure.ac} before calling @command{libtoolize}, the
4783 appropriate @code{libltdl} files will be installed automatically.
4784 @end defmac
4786 @defmac LTDL_INIT (@var{options})
4787 @defmacx LT_WITH_LTDL
4788 @defmacx AC_WITH_LTDL
4789 @code{AC_WITH_LTDL} and @code{LT_WITH_LTDL} are deprecated names for
4790 older versions of this macro; @command{autoupdate} will update your
4791 @file{configure.ac} file.
4793 This macro adds the following options to the @command{configure}
4794 script:
4796 @table @option
4797 @item --with-ltdl-include @var{installed-ltdl-header-dir}
4798 The @code{LTDL_INIT} macro will look in the standard header file
4799 locations to find the installed @code{libltdl} headers.  If
4800 @code{LTDL_INIT} can't find them by itself, the person who builds
4801 your package can use this option to tell @command{configure} where
4802 the installed @code{libltdl} headers are.
4804 @item --with-ltdl-lib @var{installed-ltdl-library-dir}
4805 Similarly, the person building your package can use this option to
4806 help @command{configure} find the installed @file{libltdl.la}.
4808 @item --with-included-ltdl
4809 If there is no installed @code{libltdl}, or in any case if the
4810 person building your package would rather use the @code{libltdl}
4811 sources shipped with the package in the subdirectory named by
4812 @code{LT_CONFIG_LTDL_DIR}, they should pass this option to
4813 @command{configure}.
4814 @end table
4816 If the @option{--with-included-ltdl} is not passed at
4817 configure time, and an installed @code{libltdl} is not
4818 found@footnote{@c
4820 Even if libltdl is installed, @samp{LTDL_INIT} may fail
4821 to detect it if libltdl depends on symbols provided by libraries
4822 other than the C library.
4824 }, then @command{configure} will exit immediately with an error that
4825 asks the user to either specify the location of an installed
4826 @code{libltdl} using the @option{--with-ltdl-include} and
4827 @option{--with-ltdl-lib} options, or to build with the
4828 @code{libltdl} sources shipped with the package by passing
4829 @option{--with-included-ltdl}.
4831 If an installed @code{libltdl} is found, then @code{LIBLTDL} is set to
4832 the link flags needed to use it, and @code{LTDLINCL} to the preprocessor
4833 flags needed to find the installed headers, and @code{LTDLDEPS} will
4834 be empty.  Note, however, that no version checking is performed.  You
4835 should manually check for the @code{libltdl} features you need in
4836 @file{configure.ac}:
4838 @example
4839 LT_INIT([dlopen])
4840 LTDL_INIT
4842 # The lt_dladvise_init symbol was added with libtool-2.2
4843 if test yes != "$with_included_ltdl"; then
4844   save_CFLAGS=$CFLAGS
4845   save_LDFLAGS=$LDFLAGS
4846   CFLAGS="$CFLAGS $LTDLINCL"
4847   LDFLAGS="$LDFLAGS $LIBLTDL"
4848   AC_CHECK_LIB([ltdl], [lt_dladvise_init],
4849                 [],
4850         [AC_MSG_ERROR([installed libltdl is too old])])
4851   LDFLAGS=$save_LDFLAGS
4852   CFLAGS=$save_CFLAGS
4854 @end example
4856 @var{options} may include no more than one of the following build
4857 modes depending on how you want your project to build @code{libltdl}:
4858 @samp{nonrecursive}, @samp{recursive}, or @samp{subproject}.  In order
4859 for @command{libtoolize} to detect this option correctly, if you
4860 supply one of these arguments, they must be given literally (i.e.,
4861 macros or shell variables that expand to the correct ltdl mode will not
4862 work).
4864 @table @samp
4865 @item nonrecursive
4866 This is how the Libtool project distribution builds the @code{libltdl}
4867 we ship and install.  If you wish to use Automake to build
4868 @code{libltdl} without invoking a recursive make to descend into the
4869 @code{libltdl} subdirectory, then use this option.  You will need to set
4870 your configuration up carefully to make this work properly, and you will
4871 need releases of Autoconf and Automake that support
4872 @code{subdir-objects} and @code{LIBOBJDIR} properly.  In your
4873 @file{configure.ac}, add:
4875 @example
4876 AM_INIT_AUTOMAKE([subdir-objects])
4877 AC_CONFIG_HEADERS([config.h])
4878 LT_CONFIG_LTDL_DIR([libltdl])
4879 LT_INIT([dlopen])
4880 LTDL_INIT([nonrecursive])
4881 @end example
4883 @noindent
4884 You @emph{have to} use a config header, but it may have a name different
4885 than @file{config.h}.
4887 Also, add the following near the top of your @file{Makefile.am}:
4889 @example
4890 AM_CPPFLAGS =
4891 AM_LDFLAGS =
4893 BUILT_SOURCES =
4894 EXTRA_DIST =
4895 CLEANFILES =
4896 MOSTLYCLEANFILES =
4898 include_HEADERS =
4899 noinst_LTLIBRARIES =
4900 lib_LTLIBRARIES =
4901 EXTRA_LTLIBRARIES =
4903 include libltdl/ltdl.mk
4904 @end example
4906 @noindent
4907 Unless you build no other libraries from this @file{Makefile.am},
4908 you will also need to change @code{lib_LTLIBRARIES} to assign with
4909 @samp{+=} so that the @code{libltdl} targets declared in
4910 @file{ltdl.mk} are not overwritten.
4912 @item recursive
4913 This build mode still requires that you use Automake, but (in contrast
4914 with @samp{nonrecursive}) uses the more usual device of starting another
4915 @code{make} process in the @file{libltdl} subdirectory.  To use this
4916 mode, you should add to your @file{configure.ac}:
4918 @example
4919 AM_INIT_AUTOMAKE
4920 AC_CONFIG_HEADERS([config.h])
4921 LT_CONFIG_LTDL_DIR([libltdl])
4922 LT_INIT([dlopen])
4923 LTDL_INIT([recursive])
4924 AC_CONFIG_FILES([libltdl/Makefile])
4925 @end example
4927 @noindent
4928 Again, you @emph{have to} use a config header, but it may have a name
4929 different than @file{config.h} if you like.
4931 Also, add this to your @file{Makefile.am}:
4933 @example
4934 SUBDIRS = libltdl
4935 @end example
4937 @item subproject
4938 This mode is the default unless you explicitly add @code{recursive} or
4939 @code{nonrecursive} to your @code{LTDL_INIT} options;  @code{subproject}
4940 is the only mode supported by previous releases of libltdl.  Even if you
4941 do not use Autoconf in the parent project, then, in @samp{subproject}
4942 mode, still @code{libltdl} contains all the necessary files to configure
4943 and build itself -- you just need to arrange for your build system to
4944 call @file{libltdl/configure} with appropriate options, and then run
4945 @code{make} in the @code{libltdl} subdirectory.
4947 If you @emph{are} using Autoconf and Automake, then you will need to add
4948 the following to your @file{configure.ac}:
4950 @example
4951 LT_CONFIG_LTDL_DIR([libltdl])
4952 LTDL_INIT
4953 @end example
4955 @noindent
4956 and to @file{Makefile.am}:
4958 @example
4959 SUBDIRS = libltdl
4960 @end example
4961 @end table
4963 Aside from setting the libltdl build mode, there are other keywords
4964 that you can pass to @code{LTDL_INIT} to modify its behavior when
4965 @option{--with-included-ltdl} has been given:
4967 @table @samp
4968 @item convenience
4969 This is the default unless you explicitly add @code{installable} to
4970 your @code{LTDL_INIT} options.
4972 This keyword will cause options to be passed to the @command{configure}
4973 script in the subdirectory named by @code{LT_CONFIG_LTDL_DIR}
4974 to cause it to be built as a convenience library.  If you're not
4975 using automake, you will need to define @code{top_build_prefix},
4976 @code{top_builddir}, and @code{top_srcdir} in your makefile so that
4977 @code{LIBLTDL}, @code{LTDLDEPS}, and @code{LTDLINCL} expand correctly.
4979 One advantage of the convenience library is that it is not installed,
4980 so the fact that you use @code{libltdl} will not be apparent to the
4981 user, and it won't overwrite a pre-installed version of
4982 @code{libltdl} the system might already have in the installation
4983 directory.  On the other hand, if you want to upgrade @code{libltdl}
4984 for any reason (e.g.@: a bugfix) you'll have to recompile your package
4985 instead of just replacing the shared installed version of
4986 @code{libltdl}.  However, if your programs or libraries are linked
4987 with other libraries that use such a pre-installed version of
4988 @code{libltdl}, you may get linker errors or run-time crashes.
4989 Another problem is that you cannot link the convenience library into
4990 more than one libtool library, then link a single program with those
4991 libraries, because you may get duplicate symbols.  In general you can
4992 safely use the convenience library in programs that don't depend on
4993 other libraries that might use @code{libltdl} too.
4995 @item installable
4996 This keyword will pass options to the @command{configure}
4997 script in the subdirectory named by @code{LT_CONFIG_LTDL_DIR}
4998 to cause it to be built as an installable library.  If you're not
4999 using automake, you will need to define @code{top_build_prefix},
5000 @code{top_builddir} and @code{top_srcdir} in your makefile so that
5001 @code{LIBLTDL}, @code{LTDLDEPS}, and @code{LTDLINCL} are expanded
5002 properly.
5004 Be aware that you could overwrite another @code{libltdl} already
5005 installed to the same directory if you use this option.
5006 @end table
5007 @end defmac
5009 Whatever method you use, @samp{LTDL_INIT} will define the shell variable
5010 @code{LIBLTDL} to the link flag that you should use to link with
5011 @code{libltdl}, the shell variable @code{LTDLDEPS} to the files that
5012 can be used as a dependency in @file{Makefile} rules, and the shell
5013 variable @code{LTDLINCL} to the preprocessor flag that you should use to
5014 compile programs that include @file{ltdl.h}. So, when you want to link a
5015 program with libltdl, be it a convenience, installed or installable
5016 library, just use @samp{$(LTDLINCL)} for preprocessing and compilation,
5017 and @samp{$(LIBLTDL)} for linking.
5019 @itemize @bullet
5020 @item
5021 If your package is built using an installed version of @code{libltdl},
5022 @code{LIBLTDL} will be set to the compiler flags needed to link against
5023 the installed library, @code{LTDLDEPS} will be empty, and @code{LTDLINCL}
5024 will be set to the compiler flags needed to find the @code{libltdl}
5025 header files.
5027 @item
5028 If your package is built using the convenience libltdl, @code{LIBLTDL}
5029 and @code{LTDLDEPS} will be the pathname for the convenience version of
5030 libltdl (starting with @samp{$@{top_builddir@}/} or
5031 @samp{$@{top_build_prefix@}}) and @code{LTDLINCL} will be @option{-I}
5032 followed by the directory that contains @file{ltdl.h} (starting with
5033 @samp{$@{top_srcdir@}/}).
5035 @item
5036 If an installable version of the included @code{libltdl} is being
5037 built, its pathname starting with @samp{$@{top_builddir@}/} or
5038 @samp{$@{top_build_prefix@}}, will be stored in @code{LIBLTDL} and
5039 @code{LTDLDEPS}, and @code{LTDLINCL} will be set just like in the case of
5040 convenience library.
5041 @end itemize
5043 You should probably also use the @samp{dlopen} option to @code{LT_INIT}
5044 in your @file{configure.ac}, otherwise libtool will assume no dlopening
5045 mechanism is supported, and revert to dlpreopening, which is probably not
5046 what you want.  Avoid using the @option{-static},
5047 @option{-static-libtool-libs}, or @option{-all-static}
5048 switches when linking programs with libltdl.  This will not work on
5049 all platforms, because the dlopening functions may not be available
5050 for static linking.
5052 The following example shows you how to embed an installable libltdl in
5053 your package.  In order to use the convenience variant, just replace the
5054 @code{LTDL_INIT} option @samp{installable} with @samp{convenience}.  We
5055 assume that libltdl was embedded using @samp{libtoolize --ltdl}.
5057 configure.ac:
5058 @example
5060 # Name the subdirectory that contains libltdl sources
5061 LT_CONFIG_LTDL_DIR([libltdl])
5063 # Configure libtool with dlopen support if possible
5064 LT_INIT([dlopen])
5066 # Enable building of the installable libltdl library
5067 LTDL_INIT([installable])
5069 @end example
5071 Makefile.am:
5072 @example
5074 SUBDIRS = libltdl
5076 AM_CPPFLAGS = $(LTDLINCL)
5078 myprog_LDFLAGS = -export-dynamic
5079 myprog_LDADD = $(LIBLTDL) -dlopen self -dlopen foo1.la
5080 myprog_DEPENDENCIES = $(LTDLDEPS) foo1.la
5082 @end example
5084 @defmac LTDL_INSTALLABLE
5085 @defmacx AC_LIBLTDL_INSTALLABLE
5086 These macros are deprecated, the @samp{installable} option to
5087 @code{LTDL_INIT} should be used instead.
5088 @end defmac
5090 @defmac LTDL_CONVENIENCE
5091 @defmacx AC_LIBLTDL_CONVENIENCE
5092 These macros are deprecated, the @samp{convenience} option to
5093 @code{LTDL_INIT} should be used instead.
5094 @end defmac
5097 @node Trace interface
5098 @chapter Libtool's trace interface
5099 @cindex trace interface
5100 @cindex autoconf traces
5102 This section describes macros whose sole purpose is to be traced using
5103 Autoconf's @option{--trace} option (@pxref{autoconf Invocation, , The
5104 Autoconf Manual, autoconf, The Autoconf Manual}) to query the Libtool
5105 configuration of a project.  These macros are called by Libtool
5106 internals and should never be called by user code; they should only be
5107 traced.
5109 @defmac LT_SUPPORTED_TAG (@var{tag})
5110 This macro is called once for each language enabled in the package.  Its
5111 only argument, @var{tag}, is the tag-name corresponding to the language
5112 (@pxref{Tags}).
5114 You can therefore retrieve the list of all tags enabled in a project
5115 using the following command:
5116 @example
5117 autoconf --trace 'LT_SUPPORTED_TAG:$1'
5118 @end example
5119 @end defmac
5122 @node FAQ
5123 @chapter Frequently Asked Questions about libtool
5125 This chapter covers some questions that often come up on the mailing
5126 lists.
5128 @menu
5129 * Stripped link flags::         Dropped flags when creating a library
5130 @end menu
5132 @node Stripped link flags
5133 @section Why does libtool strip link flags when creating a library?
5135 When creating a shared library, but not when compiling or creating
5136 a program, @command{libtool} drops some flags from the command line
5137 provided by the user.  This is done because flags unknown to
5138 @command{libtool} may interfere with library creation or require
5139 additional support from @command{libtool}, and because omitting
5140 flags is usually the conservative choice for a successful build.
5142 If you encounter flags that you think are useful to pass, as a
5143 work-around you can prepend flags with @code{-Wc,} or @code{-Xcompiler }
5144 to allow them to be passed through to the compiler driver
5145 (@pxref{Link mode}).  Another possibility is to add flags already
5146 to the compiler command at @command{configure} run time:
5148 @example
5149 ./configure CC='gcc -m64'
5150 @end example
5152 If you think @command{libtool} should let some flag through by default,
5153 here's how you can test such an inclusion: grab the Libtool development
5154 tree, edit the @file{ltmain.in} file in the @file{libltdl/config}
5155 subdirectory to pass through the flag (search for @samp{Flags to be
5156 passed through}), re-bootstrap and build with the flags in question
5157 added to @code{LDFLAGS}, @code{CFLAGS}, @code{CXXFLAGS}, etc. on the
5158 @command{configure} command line as appropriate.  Run the testsuite
5159 as described in the @file{README} file and report results to
5160 @value{BUGADDR}.
5162 @node Troubleshooting
5163 @chapter Troubleshooting
5164 @cindex troubleshooting
5165 @cindex problems, solving
5166 @cindex solving problems
5167 @cindex problems, blaming somebody else for
5169 Libtool is under constant development, changing to remain up-to-date
5170 with modern operating systems.  If libtool doesn't work the way you
5171 think it should on your platform, you should read this chapter to help
5172 determine what the problem is, and how to resolve it.
5174 @menu
5175 * Libtool test suite::          Libtool's self-tests.
5176 * Reporting bugs::              How to report problems with libtool.
5177 @end menu
5179 @node Libtool test suite
5180 @section The libtool test suite
5181 @cindex test suite
5183 Libtool comes with two integrated sets of tests to check that your build
5184 is sane, that test its capabilities, and report obvious bugs in the
5185 libtool program.  These tests, too, are constantly evolving, based on
5186 past problems with libtool, and known deficiencies in other operating
5187 systems.
5189 As described in the @file{README} file, you may run @kbd{make -k check}
5190 after you have built libtool (possibly before you install it)
5191 to make sure that it meets basic functional requirements.
5193 @menu
5194 * Test descriptions::           The contents of the old test suite.
5195 * When tests fail::             What to do when a test fails.
5196 @end menu
5198 @node Test descriptions
5199 @subsection Description of test suite
5201 Here is a list of the current programs in the old test suite, and what
5202 they test for:
5204 @table @file
5206 @item cdemo-conf.test
5207 @itemx cdemo-make.test
5208 @itemx cdemo-exec.test
5209 @itemx cdemo-static.test
5210 @itemx cdemo-static-make.test
5211 @itemx cdemo-static-exec.test
5212 @itemx cdemo-shared.test
5213 @itemx cdemo-shared-make.test
5214 @itemx cdemo-shared-exec.test
5215 @itemx cdemo-undef.test
5216 @itemx cdemo-undef-make.test
5217 @itemx cdemo-undef-exec.test
5218 @pindex cdemo-conf.test
5219 @pindex cdemo-make.test
5220 @pindex cdemo-exec.test
5221 @pindex cdemo-static.test
5222 @pindex cdemo-static-make.test
5223 @pindex cdemo-static-exec.test
5224 @pindex cdemo-shared.test
5225 @pindex cdemo-shared-make.test
5226 @pindex cdemo-shared-exec.test
5227 @pindex cdemo-undef.test
5228 @pindex cdemo-undef-make.test
5229 @pindex cdemo-undef-exec.test
5230 These programs check to see that the @file{tests/cdemo} subdirectory of
5231 the libtool distribution can be configured and built correctly.
5233 The @file{tests/cdemo} subdirectory contains a demonstration of libtool
5234 convenience libraries, a mechanism that allows build-time static
5235 libraries to be created, in a way that their components can be later
5236 linked into programs or other libraries, even shared ones.
5238 The tests matching @file{cdemo-*make.test} and @file{cdemo-*exec.test}
5239 are executed three times, under three different libtool configurations:
5240 @file{cdemo-conf.test} configures @file{cdemo/libtool} to build both
5241 static and shared libraries (the default for platforms that support
5242 both), @file{cdemo-static.test} builds only static libraries
5243 (@samp{--disable-shared}), and @file{cdemo-shared.test} builds only
5244 shared libraries (@samp{--disable-static}).
5246 The test @file{cdemo-undef.test} tests the generation of shared
5247 libraries with undefined symbols on systems that allow this.
5249 @item demo-conf.test
5250 @itemx demo-make.test
5251 @itemx demo-exec.test
5252 @itemx demo-inst.test
5253 @itemx demo-unst.test
5254 @itemx demo-static.test
5255 @itemx demo-static-make.test
5256 @itemx demo-static-exec.test
5257 @itemx demo-static-inst.test
5258 @itemx demo-static-unst.test
5259 @itemx demo-shared.test
5260 @itemx demo-shared-make.test
5261 @itemx demo-shared-exec.test
5262 @itemx demo-shared-inst.test
5263 @itemx demo-shared-unst.test
5264 @itemx demo-nofast.test
5265 @itemx demo-nofast-make.test
5266 @itemx demo-nofast-exec.test
5267 @itemx demo-nofast-inst.test
5268 @itemx demo-nofast-unst.test
5269 @itemx demo-pic.test
5270 @itemx demo-pic-make.test
5271 @itemx demo-pic-exec.test
5272 @itemx demo-nopic.test
5273 @itemx demo-nopic-make.test
5274 @itemx demo-nopic-exec.test
5275 @pindex demo-conf.test
5276 @pindex demo-make.test
5277 @pindex demo-exec.test
5278 @pindex demo-inst.test
5279 @pindex demo-unst.test
5280 @pindex demo-static.test
5281 @pindex demo-static-make.test
5282 @pindex demo-static-exec.test
5283 @pindex demo-static-inst.test
5284 @pindex demo-static-unst.test
5285 @pindex demo-shared.test
5286 @pindex demo-shared-make.test
5287 @pindex demo-shared-exec.test
5288 @pindex demo-shared-inst.test
5289 @pindex demo-shared-unst.test
5290 @pindex demo-nofast.test
5291 @pindex demo-nofast-make.test
5292 @pindex demo-nofast-exec.test
5293 @pindex demo-nofast-inst.test
5294 @pindex demo-nofast-unst.test
5295 @pindex demo-pic.test
5296 @pindex demo-pic-make.test
5297 @pindex demo-pic-exec.test
5298 @pindex demo-nopic.test
5299 @pindex demo-nopic-make.test
5300 @pindex demo-nopic-exec.test
5301 These programs check to see that the @file{tests/demo} subdirectory of
5302 the libtool distribution can be configured, built, installed, and
5303 uninstalled correctly.
5305 The @file{tests/demo} subdirectory contains a demonstration of a trivial
5306 package that uses libtool.  The tests matching @file{demo-*make.test},
5307 @file{demo-*exec.test}, @file{demo-*inst.test} and
5308 @file{demo-*unst.test} are executed four times, under four different
5309 libtool configurations: @file{demo-conf.test} configures
5310 @file{demo/libtool} to build both static and shared libraries,
5311 @file{demo-static.test} builds only static libraries
5312 (@option{--disable-shared}), and @file{demo-shared.test} builds only
5313 shared libraries (@option{--disable-static}).
5314 @file{demo-nofast.test} configures @file{demo/libtool} to
5315 disable the fast-install mode (@option{--enable-fast-install=no}).
5316 @file{demo-pic.test} configures @file{demo/libtool} to
5317 prefer building PIC code (@option{--with-pic}), @file{demo-nopic.test}
5318 to prefer non-PIC code (@option{--without-pic}).
5320 @item demo-deplibs.test
5321 @pindex demo-deplibs.test
5322 Many systems cannot link static libraries into shared libraries.
5323 libtool uses a @code{deplibs_check_method} to prevent such cases.
5324 This tests checks whether libtool's @code{deplibs_check_method}
5325 works properly.
5327 @item demo-hardcode.test
5328 @pindex demo-hardcode.test
5329 On all systems with shared libraries, the location of the library can be
5330 encoded in executables that are linked against it @pxref{Linking
5331 executables}.  This test checks under what conditions your system
5332 linker hardcodes the library location, and guarantees that they
5333 correspond to libtool's own notion of how your linker behaves.
5335 @item demo-relink.test
5336 @itemx depdemo-relink.test
5337 @pindex demo-relink.test
5338 @pindex depdemo-relink.test
5339 These tests check whether variable @code{shlibpath_overrides_runpath} is
5340 properly set.  If the test fails, it will indicate what the variable should
5341 have been set to.
5343 @item demo-noinst-link.test
5344 @pindex demo-noinst-link.test
5345 Checks whether libtool will not try to link with a previously installed
5346 version of a library when it should be linking with a just-built one.
5348 @item depdemo-conf.test
5349 @itemx depdemo-make.test
5350 @itemx depdemo-exec.test
5351 @itemx depdemo-inst.test
5352 @itemx depdemo-unst.test
5353 @itemx depdemo-static.test
5354 @itemx depdemo-static-make.test
5355 @itemx depdemo-static-exec.test
5356 @itemx depdemo-static-inst.test
5357 @itemx depdemo-static-unst.test
5358 @itemx depdemo-shared.test
5359 @itemx depdemo-shared-make.test
5360 @itemx depdemo-shared-exec.test
5361 @itemx depdemo-shared-inst.test
5362 @itemx depdemo-shared-unst.test
5363 @itemx depdemo-nofast.test
5364 @itemx depdemo-nofast-make.test
5365 @itemx depdemo-nofast-exec.test
5366 @itemx depdemo-nofast-inst.test
5367 @itemx depdemo-nofast-unst.test
5368 @pindex depdemo-conf.test
5369 @pindex depdemo-make.test
5370 @pindex depdemo-exec.test
5371 @pindex depdemo-inst.test
5372 @pindex depdemo-unst.test
5373 @pindex depdemo-static.test
5374 @pindex depdemo-static-make.test
5375 @pindex depdemo-static-exec.test
5376 @pindex depdemo-static-inst.test
5377 @pindex depdemo-static-unst.test
5378 @pindex depdemo-shared.test
5379 @pindex depdemo-shared-make.test
5380 @pindex depdemo-shared-exec.test
5381 @pindex depdemo-shared-inst.test
5382 @pindex depdemo-shared-unst.test
5383 @pindex depdemo-nofast.test
5384 @pindex depdemo-nofast-make.test
5385 @pindex depdemo-nofast-exec.test
5386 @pindex depdemo-nofast-inst.test
5387 @pindex depdemo-nofast-unst.test
5388 These programs check to see that the @file{tests/depdemo} subdirectory
5389 of the libtool distribution can be configured, built, installed, and
5390 uninstalled correctly.
5392 The @file{tests/depdemo} subdirectory contains a demonstration of
5393 inter-library dependencies with libtool.  The test programs link some
5394 interdependent libraries.
5396 The tests matching @file{depdemo-*make.test}, @file{depdemo-*exec.test},
5397 @file{depdemo-*inst.test} and @file{depdemo-*unst.test} are executed
5398 four times, under four different libtool configurations:
5399 @file{depdemo-conf.test} configures @file{depdemo/libtool} to build both
5400 static and shared libraries, @file{depdemo-static.test} builds only static
5401 libraries (@option{--disable-shared}), and @file{depdemo-shared.test} builds
5402 only shared libraries (@option{--disable-static}).
5403 @file{depdemo-nofast.test} configures @file{depdemo/libtool} to
5404 disable the fast-install mode (@option{--enable-fast-install=no}).
5406 @item mdemo-conf.test
5407 @itemx mdemo-make.test
5408 @itemx mdemo-exec.test
5409 @itemx mdemo-inst.test
5410 @itemx mdemo-unst.test
5411 @itemx mdemo-static.test
5412 @itemx mdemo-static-make.test
5413 @itemx mdemo-static-exec.test
5414 @itemx mdemo-static-inst.test
5415 @itemx mdemo-static-unst.test
5416 @itemx mdemo-shared.test
5417 @itemx mdemo-shared-make.test
5418 @itemx mdemo-shared-exec.test
5419 @itemx mdemo-shared-inst.test
5420 @itemx mdemo-shared-unst.test
5421 @pindex mdemo-conf.test
5422 @pindex mdemo-make.test
5423 @pindex mdemo-exec.test
5424 @pindex mdemo-inst.test
5425 @pindex mdemo-unst.test
5426 @pindex mdemo-static.test
5427 @pindex mdemo-static-make.test
5428 @pindex mdemo-static-exec.test
5429 @pindex mdemo-static-inst.test
5430 @pindex mdemo-static-unst.test
5431 @pindex mdemo-shared.test
5432 @pindex mdemo-shared-make.test
5433 @pindex mdemo-shared-exec.test
5434 @pindex mdemo-shared-inst.test
5435 @pindex mdemo-shared-unst.test
5436 These programs check to see that the @file{tests/mdemo} subdirectory of
5437 the libtool distribution can be configured, built, installed, and
5438 uninstalled correctly.
5440 The @file{tests/mdemo} subdirectory contains a demonstration of a
5441 package that uses libtool and the system independent dlopen wrapper
5442 @file{libltdl} to load modules.  The library @file{libltdl} provides a
5443 dlopen wrapper for various platforms (POSIX)
5444 including support for dlpreopened modules (@pxref{Dlpreopening}).
5446 The tests matching @file{mdemo-*make.test}, @file{mdemo-*exec.test},
5447 @file{mdemo-*inst.test} and @file{mdemo-*unst.test} are executed
5448 three times, under three different libtool configurations:
5449 @file{mdemo-conf.test} configures @file{mdemo/libtool} to build both
5450 static and shared libraries, @file{mdemo-static.test} builds only static
5451 libraries (@option{--disable-shared}), and @file{mdemo-shared.test} builds
5452 only shared libraries (@option{--disable-static}).
5454 @item mdemo-dryrun.test
5455 @pindex mdemo-dryrun.test
5456 This test checks whether libtool's @option{--dry-run} mode works properly.
5458 @item mdemo2-conf.test
5459 @itemx mdemo2-exec.test
5460 @itemx mdemo2-make.test
5461 @pindex mdemo2-conf.test
5462 @pindex mdemo2-exec.test
5463 @pindex mdemo2-make.test
5464 These programs check to see that the @file{tests/mdemo2} subdirectory of
5465 the libtool distribution can be configured, built, and executed
5466 correctly.
5468 The @file{tests/mdemo2} directory contains a demonstration of a package
5469 that attempts to link with a library (from the @file{tests/mdemo}
5470 directory) that itself does dlopening of libtool modules.
5472 @item link.test
5473 @pindex link.test
5474 This test guarantees that linking directly against a non-libtool static
5475 library works properly.
5477 @item link-2.test
5478 @pindex link-2.test
5479 This test makes sure that files ending in @file{.lo} are never linked
5480 directly into a program file.
5482 @item nomode.test
5483 @pindex nomode.test
5484 Check whether we can actually get help for libtool.
5486 @item objectlist.test
5487 @pindex objectlist.test
5488 Check that a nonexistent objectlist file is properly detected.
5490 @item pdemo-conf.test
5491 @itemx pdemo-make.test
5492 @itemx pdemo-exec.test
5493 @itemx pdemo-inst.test
5494 @pindex pdemo-conf.test
5495 @pindex pdemo-make.test
5496 @pindex pdemo-exec.test
5497 @pindex pdemo-inst.test
5498 These programs check to see that the @file{tests/pdemo} subdirectory of
5499 the libtool distribution can be configured, built, and executed
5500 correctly.
5502 The @file{pdemo-conf.test} lowers the @code{max_cmd_len} variable in the
5503 generated libtool script to test the measures to evade command line
5504 length limitations.
5506 @item quote.test
5507 @pindex quote.test
5508 This program checks libtool's metacharacter quoting.
5510 @item sh.test
5511 @pindex sh.test
5512 Checks for some nonportable or dubious or undesired shell constructs in
5513 shell scripts.
5515 @item suffix.test
5516 @pindex suffix.test
5517 When other programming languages are used with libtool (@pxref{Other
5518 languages}), the source files may end in suffixes other than @file{.c}.
5519 This test validates that libtool can handle suffixes for all the file
5520 types that it supports, and that it fails when the suffix is invalid.
5522 @item tagdemo-conf.test
5523 @itemx tagdemo-make.test
5524 @itemx tagdemo-exec.test
5525 @itemx tagdemo-static.test
5526 @itemx tagdemo-static-make.test
5527 @itemx tagdemo-static-exec.test
5528 @itemx tagdemo-shared.test
5529 @itemx tagdemo-shared-make.test
5530 @itemx tagdemo-shared-exec.test
5531 @itemx tagdemo-undef.test
5532 @itemx tagdemo-undef-make.test
5533 @itemx tagdemo-undef-exec.test
5534 @pindex tagdemo-conf.test
5535 @pindex tagdemo-make.test
5536 @pindex tagdemo-exec.test
5537 @pindex tagdemo-static.test
5538 @pindex tagdemo-static-make.test
5539 @pindex tagdemo-static-exec.test
5540 @pindex tagdemo-shared.test
5541 @pindex tagdemo-shared-make.test
5542 @pindex tagdemo-shared-exec.test
5543 @pindex tagdemo-undef.test
5544 @pindex tagdemo-undef-make.test
5545 @pindex tagdemo-undef-exec.test
5546 These programs check to see that the @file{tests/tagdemo} subdirectory
5547 of the libtool distribution can be configured, built, and executed
5548 correctly.
5550 The @file{tests/tagdemo} directory contains a demonstration of a package
5551 that uses libtool's multi-language support through configuration tags.
5552 It generates a library from C++ sources, which is then linked to a C++
5553 program.
5555 @item f77demo-conf.test
5556 @itemx f77demo-make.test
5557 @itemx f77demo-exec.test
5558 @itemx f77demo-static.test
5559 @itemx f77demo-static-make.test
5560 @itemx f77demo-static-exec.test
5561 @itemx f77demo-shared.test
5562 @itemx f77demo-shared-make.test
5563 @itemx f77demo-shared-exec.test
5564 @pindex f77demo-conf.test
5565 @pindex f77demo-make.test
5566 @pindex f77demo-exec.test
5567 @pindex f77demo-static.test
5568 @pindex f77demo-static-make.test
5569 @pindex f77demo-static-exec.test
5570 @pindex f77demo-shared.test
5571 @pindex f77demo-shared-make.test
5572 @pindex f77demo-shared-exec.test
5573 These programs check to see that the @file{tests/f77demo} subdirectory
5574 of the libtool distribution can be configured, built, and executed
5575 correctly.
5577 The @file{tests/f77demo} tests test Fortran 77 support in libtool by
5578 creating libraries from Fortran 77 sources, and mixed Fortran and C
5579 sources, and a Fortran 77 program to use the former library, and a C
5580 program to use the latter library.
5582 @item fcdemo-conf.test
5583 @itemx fcdemo-make.test
5584 @itemx fcdemo-exec.test
5585 @itemx fcdemo-static.test
5586 @itemx fcdemo-static-make.test
5587 @itemx fcdemo-static-exec.test
5588 @itemx fcdemo-shared.test
5589 @itemx fcdemo-shared-make.test
5590 @itemx fcdemo-shared-exec.test
5591 @pindex fcdemo-conf.test
5592 @pindex fcdemo-make.test
5593 @pindex fcdemo-exec.test
5594 @pindex fcdemo-static.test
5595 @pindex fcdemo-static-make.test
5596 @pindex fcdemo-static-exec.test
5597 @pindex fcdemo-shared.test
5598 @pindex fcdemo-shared-make.test
5599 @pindex fcdemo-shared-exec.test
5600 These programs check to see that the @file{tests/fcdemo} subdirectory
5601 of the libtool distribution can be configured, built, and executed
5602 correctly.
5604 The @file{tests/fcdemo} is similar to the @file{tests/f77demo}
5605 directory, except that Fortran 90 is used in combination with the
5606 @samp{FC} interface provided by Autoconf and Automake.
5608 @end table
5610 The new, Autotest-based test suite uses keywords to classify certain
5611 test groups:
5613 @table @samp
5614 @item CXX
5615 @itemx F77
5616 @itemx FC
5617 @itemx GCJ
5618 The test group exercises one of these @command{libtool} language tags.
5620 @item autoconf
5621 @itemx automake
5622 These keywords denote that the respective external program is needed
5623 by the test group.  The tests are typically skipped if the program is
5624 not installed.  The @samp{automake} keyword may also denote use of the
5625 @command{aclocal} program.
5627 @item interactive
5628 This test group may require user interaction on some systems.  Typically,
5629 this means closing a popup window about a DLL load error on Windows.
5631 @item libltdl
5632 Denote that the @file{libltdl} library is exercised by the test group.
5634 @item libtool
5635 @itemx libtoolize
5636 Denote that the @command{libtool} or @command{libtoolize} scripts are
5637 exercised by the test group, respectively.
5639 @item recursive
5640 Denote that this test group may recursively re-invoke the test suite
5641 itself, with changed settings and maybe a changed @command{libtool}
5642 script.  You may use the @env{INNER_TESTSUITEFLAGS} variable to pass
5643 additional settings to this recursive invocation.  Typically, recursive
5644 invocations delimit the set of tests with another keyword, for example
5645 by passing @code{-k libtool} right before the expansion of the
5646 @env{INNER_TESTSUITEFLAGS} variable (without an intervening space, so
5647 you get the chance for further delimitation).
5649 Test groups with the keyword @samp{recursive} should not be denoted with
5650 keywords, in order to avoid infinite recursion.  As a consequence,
5651 recursive test groups themselves should never require user interaction,
5652 while the test groups they invoke may do so.
5653 @end table
5655 @cindex @samp{check-interactive}
5656 @cindex @samp{check-noninteractive}
5657 There is a convenience target @samp{check-noninteractive} that runs
5658 all tests from both test suites that do not cause user interaction on
5659 Windows.  Conversely, the target @samp{check-interactive} runs the
5660 complement of tests and might require closing popup windows about DLL
5661 load errors on Windows.
5664 @node When tests fail
5665 @subsection When tests fail
5666 @cindex failed tests
5667 @cindex tests, failed
5669 When the tests in the old test suite are run via @command{make check},
5670 output is caught in per-test @file{tests/@var{test-name}.log} files
5671 and summarized in the @file{test-suite.log} file.  The exit status of each
5672 program tells the @file{Makefile} whether or not the test succeeded.
5674 If a test fails, it means that there is either a programming error in
5675 libtool, or in the test program itself.
5677 To investigate a particular test, you may run it directly, as you would
5678 a normal program.  When the test is invoked in this way, it produces
5679 output that may be useful in determining what the problem is.
5681 The new, Autotest-based test suite produces as output a file
5682 @file{tests/testsuite.log} that contains information about failed
5683 tests.
5685 You can pass options to the test suite through the @command{make}
5686 variable @env{TESTSUITEFLAGS} (@pxref{testsuite Invocation, ,
5687 The Autoconf Manual, autoconf, The Autoconf Manual}).
5690 @node Reporting bugs
5691 @section Reporting bugs
5692 @cindex bug reports
5693 @cindex reporting bugs
5694 @cindex problem reports
5696 If you think you have discovered a bug in libtool, you should think
5697 twice: the libtool maintainer is notorious for passing the buck (or
5698 maybe that should be ``passing the bug'').  Libtool was invented to fix
5699 known deficiencies in shared library implementations, so, in a way, most
5700 of the bugs in libtool are actually bugs in other operating systems.
5701 However, the libtool maintainer would definitely be happy to add support
5702 for somebody else's buggy operating system.  [I wish there was a good
5703 way to do winking smiley-faces in Texinfo.]
5705 Genuine bugs in libtool include problems with shell script portability,
5706 documentation errors, and failures in the test suite (@pxref{Libtool
5707 test suite}).
5709 First, check the documentation and help screens to make sure that the
5710 behaviour you think is a problem is not already mentioned as a feature.
5712 Then, you should read the Emacs guide to reporting bugs (@pxref{Bugs, ,
5713 Reporting Bugs, emacs, The Emacs Manual}).  Some of the details
5714 listed there are specific to Emacs, but the principle behind them is a
5715 general one.
5717 Finally, send a bug report to @value{BUGADDR} with any appropriate
5718 @emph{facts}, such as test suite output (@pxref{When tests fail}), all
5719 the details needed to reproduce the bug, and a brief description of why
5720 you think the behaviour is a bug.  Be sure to include the word
5721 ``libtool'' in the subject line, as well as the version number you are
5722 using (which can be found by typing @kbd{libtool --version}).
5724 @node Maintaining
5725 @chapter Maintenance notes for libtool
5727 This chapter contains information that the libtool maintainer finds
5728 important.  It will be of no use to you unless you are considering
5729 porting libtool to new systems, or writing your own libtool.
5731 @menu
5732 * New ports::                   How to port libtool to new systems.
5733 * Tested platforms::            When libtool was last tested.
5734 * Platform quirks::             Information about different library systems.
5735 * libtool script contents::     Configuration information that libtool uses.
5736 * Cheap tricks::                Making libtool maintainership easier.
5737 @end menu
5739 @node New ports
5740 @section Porting libtool to new systems
5742 Before you embark on porting libtool to an unsupported system, it is
5743 worthwhile to send e-mail to @value{MAILLIST}, to make sure that you are
5744 not duplicating existing work.
5746 If you find that any porting documentation is missing, please complain!
5747 Complaints with patches and improvements to the documentation, or to
5748 libtool itself, are more than welcome.
5750 @menu
5751 * Information sources::         Where to find relevant documentation
5752 * Porting inter-library dependencies::  Implementation details explained
5753 @end menu
5755 @node Information sources
5756 @subsection Information sources
5758 Once it is clear that a new port is necessary, you'll generally need the
5759 following information:
5761 @table @asis
5762 @item canonical system name
5763 You need the output of @code{config.guess} for this system, so that you
5764 can make changes to the libtool configuration process without affecting
5765 other systems.
5767 @item man pages for @command{ld} and @command{cc}
5768 These generally describe what flags are used to generate PIC, to create
5769 shared libraries, and to link against only static libraries.  You may
5770 need to follow some cross references to find the information that is
5771 required.
5773 @item man pages for @command{ld.so}, @command{rtld}, or equivalent
5774 These are a valuable resource for understanding how shared libraries are
5775 loaded on the system.
5777 @item man page for @command{ldconfig}, or equivalent
5778 This page usually describes how to install shared libraries.
5780 @item output from @kbd{ls -l /lib /usr/lib}
5781 This shows the naming convention for shared libraries on the system,
5782 including what names should be symbolic links.
5784 @item any additional documentation
5785 Some systems have special documentation on how to build and install
5786 shared libraries.
5787 @end table
5789 If you know how to program the Bourne shell, then you can complete the
5790 port yourself; otherwise, you'll have to find somebody with the relevant
5791 skills who will do the work.  People on the libtool mailing list are
5792 usually willing to volunteer to help you with new ports, so you can send
5793 the information to them.
5795 To do the port yourself, you'll definitely need to modify the
5796 @code{libtool.m4} macros to make platform-specific changes to
5797 the configuration process.  You should search that file for the
5798 @code{PORTME} keyword, which will give you some hints on what you'll
5799 need to change.  In general, all that is involved is modifying the
5800 appropriate configuration variables (@pxref{libtool script contents}).
5802 Your best bet is to find an already-supported system that is similar to
5803 yours, and make your changes based on that.  In some cases, however,
5804 your system will differ significantly from every other supported system,
5805 and it may be necessary to add new configuration variables, and modify
5806 the @code{ltmain.in} script accordingly.  Be sure to write to the
5807 mailing list before you make changes to @code{ltmain.in}, since they may
5808 have advice on the most effective way of accomplishing what you want.
5810 @node Porting inter-library dependencies
5811 @subsection Porting inter-library dependencies support
5812 @cindex inter-library dependency
5813 @vindex deplibs_check_method
5815 Since version 1.2c, libtool has re-introduced the ability to do
5816 inter-library dependency on some platforms, thanks to a patch by Toshio
5817 Kuratomi @email{badger@@prtr-13.ucsc.edu}.  Here's a shortened version
5818 of the message that contained his patch:
5820 The basic architecture is this: in @file{libtool.m4}, the person who
5821 writes libtool makes sure @samp{$deplibs} is included in
5822 @samp{$archive_cmds} somewhere and also sets the variable
5823 @samp{$deplibs_check_method}, and maybe @samp{$file_magic_cmd} when
5824 @samp{deplibs_check_method} is file_magic.
5826 @samp{deplibs_check_method} can be one of five things:
5827 @table @samp
5828 @item file_magic [@var{regex}]
5829 @vindex file_magic
5830 @vindex file_magic_cmd
5831 @vindex file_magic_test_file
5832 looks in the library link path for libraries that have the right
5833 libname.  Then it runs @samp{$file_magic_cmd} on the library and checks
5834 for a match against the extended regular expression @var{regex}.  When
5835 @code{file_magic_test_file} is set by @file{libtool.m4}, it is used as an
5836 argument to @samp{$file_magic_cmd} to verify whether the
5837 regular expression matches its output, and warn the user otherwise.
5839 @item test_compile
5840 @vindex test_compile
5841 just checks whether it is possible to link a program out of a list of
5842 libraries, and checks which of those are listed in the output of
5843 @code{ldd}.  It is currently unused, and will probably be dropped in the
5844 future.
5846 @item pass_all
5847 @vindex pass_all
5848 will pass everything without any checking.  This may work on platforms
5849 where code is position-independent by default and inter-library
5850 dependencies are properly supported by the dynamic linker, for example,
5851 on DEC OSF/1 3 and 4.
5853 @item none
5854 @vindex none
5855 It causes deplibs to be reassigned @samp{deplibs=""}.  That way
5856 @samp{archive_cmds} can contain deplibs on all platforms, but not have
5857 deplibs used unless needed.
5859 @item unknown
5860 @vindex unknown
5861 is the default for all systems unless overridden in @file{libtool.m4}.
5862 It is the same as @samp{none}, but it documents that we really don't
5863 know what the correct value should be, and we welcome patches that
5864 improve it.
5865 @end table
5867 Then in @file{ltmain.in} we have the real workhorse: a little
5868 initialization and postprocessing (to setup/release variables for use
5869 with eval echo libname_spec etc.) and a case statement that decides
5870 the method that is being used.  This is the real code@dots{} I wish I could
5871 condense it a little more, but I don't think I can without function
5872 calls.  I've mostly optimized it (moved things out of loops, etc.) but
5873 there is probably some fat left.  I thought I should stop while I was
5874 ahead, work on whatever bugs you discover, etc.@: before thinking about
5875 more than obvious optimizations.
5877 @node Tested platforms
5878 @section Tested platforms
5880 This table describes when libtool was last known to be tested on
5881 platforms where it claims to support shared libraries:
5883 @example
5884 @include PLATFORMS
5885 @end example
5887 Note: The vendor-distributed HP-UX @command{sed}(1) programs are horribly
5888 broken, and cannot handle libtool's requirements, so users may report
5889 unusual problems.  There is no workaround except to install a working
5890 @command{sed} (such as GNU @command{sed}) on these systems.
5892 Note: The vendor-distributed NCR MP-RAS @command{cc} programs emits
5893 copyright on standard error that confuse tests on size of
5894 @file{conftest.err}.  The workaround is to specify @code{CC}
5895 when run @code{configure} with @kbd{CC='cc -Hnocopyr'}.
5897 @node Platform quirks
5898 @section Platform quirks
5900 This section is dedicated to the sanity of the libtool maintainers.  It
5901 describes the programs that libtool uses, how they vary from system to
5902 system, and how to test for them.
5904 Because libtool is a shell script, it can be difficult to understand
5905 just by reading it from top to bottom.  This section helps show why
5906 libtool does things a certain way.  Combined with the scripts
5907 themselves, you should have a better sense of how to improve libtool, or
5908 write your own.
5910 @menu
5911 * References::                  Finding more information.
5912 * Compilers::                   Creating object files from source files.
5913 * Reloadable objects::          Binding object files together.
5914 * Multiple dependencies::       Removing duplicate dependent libraries.
5915 * Archivers::                   Programs that create static archives.
5916 * Cross compiling::             Issues that arise when cross compiling.
5917 * File name conversion::        Converting file names between platforms.
5918 * Windows DLLs::                Windows header defines.
5919 @end menu
5921 @node References
5922 @subsection References
5924 The following is a list of valuable documentation references:
5926 @itemize @bullet
5927 @item
5928 SGI's IRIX Manual Pages can be found at@*
5929 @url{http://techpubs.sgi.com/cgi-bin/infosrch.cgi?cmd=browse&db=man}.
5931 @item
5932 Sun's free service area
5933 (@url{http://www.sun.com/service/online/free.html}) and documentation
5934 server (@url{http://docs.sun.com/}).
5936 @item
5937 Compaq's Tru64 UNIX online documentation is at@*
5938 (@url{http://tru64unix.compaq.com/faqs/publications/pub_page/doc_list.html})
5939 with C++ documentation at@*
5940 (@url{http://tru64unix.compaq.com/cplus/docs/index.htm}).
5942 @item
5943 Hewlett-Packard has online documentation at
5944 (@url{http://docs.hp.com/index.html}).
5946 @item
5947 IBM has online documentation at
5948 (@url{http://www.rs6000.ibm.com/resource/aix_resource/Pubs/}).
5949 @end itemize
5951 @node Compilers
5952 @subsection Compilers
5954 The only compiler characteristics that affect libtool are the flags
5955 needed (if any) to generate PIC objects.  In general, if a C compiler
5956 supports certain PIC flags, then any derivative compilers support the
5957 same flags.  Until there are some noteworthy exceptions to this rule,
5958 this section will document only C compilers.
5960 The following C compilers have standard command line options, regardless
5961 of the platform:
5963 @table @code
5964 @item gcc
5966 This is the GNU C compiler, which is also the system compiler for many
5967 free operating systems (FreeBSD, GNU/Hurd, GNU/Linux, Lites, NetBSD, and
5968 OpenBSD, to name a few).
5970 The @option{-fpic} or @option{-fPIC} flags can be used to generate
5971 position-independent code.  @option{-fPIC} is guaranteed to generate
5972 working code, but the code is slower on m68k, m88k, and SPARC chips.
5973 However, using @option{-fpic} on those chips imposes arbitrary size limits
5974 on the shared libraries.
5975 @end table
5977 The rest of this subsection lists compilers by the operating system that
5978 they are bundled with:
5980 @c FIXME these should all be better-documented
5982 @table @code
5983 @item aix3*
5984 @itemx aix4*
5985 Most AIX compilers have no PIC flags, since AIX (with the exception of
5986 AIX for IA-64) runs on PowerPC and RS/6000 chips. @footnote{All code compiled
5987 for the PowerPC and RS/6000 chips (@code{powerpc-*-*}, @code{powerpcle-*-*},
5988 and @code{rs6000-*-*}) is position-independent, regardless of the operating
5989 system or compiler suite.  So, ``regular objects'' can be used to build
5990 shared libraries on these systems and no special PIC compiler flags are
5991 required.}
5993 @item hpux10*
5994 Use @samp{+Z} to generate PIC.
5996 @item osf3*
5997 Digital/UNIX 3.x does not have PIC flags, at least not on the PowerPC
5998 platform.
6000 @item solaris2*
6001 Use @option{-KPIC} to generate PIC.
6003 @item sunos4*
6004 Use @option{-PIC} to generate PIC.
6005 @end table
6007 @node Reloadable objects
6008 @subsection Reloadable objects
6010 On all known systems, a reloadable object can be created by running
6011 @kbd{ld -r -o @var{output}.o @var{input1}.o @var{input2}.o}.  This
6012 reloadable object may be treated as exactly equivalent to other
6013 objects.
6015 @node Multiple dependencies
6016 @subsection Multiple dependencies
6018 On most modern platforms the order where dependent libraries are listed
6019 has no effect on object generation.  In theory, there are platforms
6020 that require libraries that provide missing symbols to other libraries
6021 to be listed after those libraries whose symbols they provide.
6023 Particularly, if a pair of static archives each resolve some of the
6024 other's symbols, it might be necessary to list one of those archives
6025 both before and after the other one.  Libtool does not currently cope
6026 with this situation well, since duplicate libraries are removed from
6027 the link line by default.  Libtool provides the command line option
6028 @option{--preserve-dup-deps} to preserve all duplicate dependencies
6029 in cases where it is necessary.
6031 @node Archivers
6032 @subsection Archivers
6034 On all known systems, building a static library can be accomplished by
6035 running @kbd{ar cr lib@var{name}.a @var{obj1}.o @var{obj2}.o @dots{}},
6036 where the @file{.a} file is the output library, and each @file{.o} file is an
6037 object file.
6039 On all known systems, if there is a program named @command{ranlib}, then it
6040 must be used to ``bless'' the created library before linking against it,
6041 with the @kbd{ranlib lib@var{name}.a} command.  Some systems, like Irix,
6042 use the @code{ar ts} command, instead.
6044 @node Cross compiling
6045 @subsection Cross compiling
6046 @cindex cross compile
6048 Most build systems support the ability to compile libraries and applications
6049 on one platform for use on a different platform, provided a compiler capable
6050 of generating the appropriate output is available.  In such cross compiling
6051 scenarios, the platform where the libraries or applications are compiled
6052 is called the @dfn{build platform}, while the platform where the libraries
6053 or applications are intended to be used or executed is called the
6054 @dfn{host platform}.
6055 @ref{GNU Build System,, The GNU Build System, automake, The Automake Manual},
6056 of which libtool is a part, supports cross compiling via arguments passed to
6057 the configure script: @option{--build=...} and @option{--host=...}. However,
6058 when the build platform and host platform are very different, libtool is
6059 required to make certain accommodations to support these scenarios.
6061 In most cases, because the build platform and host platform differ, the
6062 cross-compiled libraries and executables can't be executed or tested on the
6063 build platform where they were compiled.  The testsuites of most build systems
6064 will often skip any tests that involve executing such foreign executables when
6065 cross-compiling.  However, if the build platform and host platform are
6066 sufficiently similar, it is often possible to run cross-compiled applications.
6067 Libtool's own testsuite often attempts to execute cross-compiled tests, but
6068 will mark any failures as @emph{skipped} since the failure might simply be due
6069 to the differences between the two platforms.
6071 In addition to cases where the host platform and build platform are extremely
6072 similar (e.g. @samp{i586-pc-linux-gnu} and @samp{i686-pc-linux-gnu}), there is
6073 another case where cross-compiled host applications may be executed on the
6074 build platform.  This is possible when the build platform supports an emulation
6075 or API-enhanced environment for the host platform.  One example of this
6076 situation would be if the build platform were MinGW, and the host platform were
6077 Cygwin (or vice versa).  Both of these platforms can actually operate within a
6078 single Windows instance, so Cygwin applications can be launched from a MinGW
6079 context, and vice versa---provided certain care is taken.  Another example
6080 would be if the build platform were GNU/Linux on an x86 32bit processor, and
6081 the host platform were MinGW.  In this situation, the
6082 @uref{http://www.winehq.org/, Wine} environment can be used to launch Windows
6083 applications from the GNU/Linux operating system; again, provided certain care
6084 is taken.
6086 One particular issue occurs when a Windows platform such as MinGW, Cygwin, or
6087 MSYS is the host or build platform, while the other platform is a Unix-style
6088 system.  In these cases, there are often conflicts between the format of the
6089 file names and paths expected within host platform libraries and executables,
6090 and those employed on the build platform.
6092 This situation is best described using a concrete example: suppose the build
6093 platform is GNU/Linux with canonical triplet @samp{i686-pc-linux-gnu}.  Suppose
6094 further that the host platform is MinGW with canonical triplet
6095 @samp{i586-pc-mingw32}.  On the GNU/Linux platform there is a cross compiler
6096 following the usual naming conventions of such compilers, where the compiler
6097 name is prefixed by the host canonical triplet (or suitable alias).  (For more
6098 information concerning canonical triplets and platform aliases, see
6099 @ref{Specifying Target Triplets,, Specifying Target Triplets, autoconf,
6100 The Autoconf Manual} and @ref{Canonicalizing,, Canonicalizing, autoconf,
6101 The Autoconf Manual})  In this case, the C compiler is named
6102 @samp{i586-pc-mingw32-gcc}.
6104 As described in @ref{Wrapper executables}, for the MinGW host platform libtool
6105 uses a wrapper executable to set various environment variables before launching
6106 the actual program executable.  Like the program executable, the wrapper
6107 executable is cross-compiled for the host platform (that is, for MinGW).  As
6108 described above, ordinarily a host platform executable cannot be executed on
6109 the build platform, but in this case the Wine environment could be used to
6110 launch the MinGW application from GNU/Linux.  However, the wrapper executable,
6111 as a host platform (MinGW) application, must set the @env{PATH} variable so
6112 that the true application's dependent libraries can be located---but the
6113 contents of the @env{PATH} variable must be structured for MinGW.  Libtool
6114 must use the Wine file name mapping facilities to determine the correct value
6115 so that the wrapper executable can set the @env{PATH} variable to point to the
6116 correct location.
6118 For example, suppose we are compiling an application in @file{/var/tmp} on
6119 GNU/Linux, using separate source code and build directories:
6121 @example
6122 @multitable @columnfractions 0.5 0.5
6123 @item @file{/var/tmp/foo-1.2.3/app/} @tab (application source code)
6124 @item @file{/var/tmp/foo-1.2.3/lib/} @tab (library source code)
6125 @item @file{/var/tmp/BUILD/app/} @tab (application build objects here)
6126 @item @file{/var/tmp/BUILD/lib/} @tab (library build objects here)
6127 @end multitable
6128 @end example
6130 Since the library will be built in @file{/var/tmp/BUILD/lib}, the wrapper
6131 executable (which will be in @file{/var/tmp/BUILD/app}) must add that
6132 directory to @env{PATH} (actually, it must add the directory named
6133 @var{objdir} under @file{/var/tmp/BUILD/lib}, but we'll ignore that detail
6134 for now).  However, Windows does not have a concept of Unix-style file or
6135 directory names such as @file{/var/tmp/BUILD/lib}.  Therefore, Wine provides
6136 a mapping from Windows file names such as @file{C:\Program Files} to specific
6137 Unix-style file names.  Wine also provides a utility that can be used to map
6138 Unix-style file names to Windows file names.
6140 In this case, the wrapper executable should actually add the value
6142 @example
6143 Z:\var\tmp\BUILD\lib
6144 @end example
6146 @noindent
6147 to the @env{PATH}.  libtool contains support for path conversions of this
6148 type, for a certain limited set of build and host platform combinations. In
6149 this case, libtool will invoke Wine's @command{winepath} utility to ensure that
6150 the correct @env{PATH} value is used.  @xref{File name conversion}.
6152 @node File name conversion
6153 @subsection File name conversion
6154 @cindex file name conversion
6155 @cindex path conversion
6157 In certain situations, libtool must convert file names and paths between
6158 formats appropriate to different platforms.  Usually this occurs when
6159 cross-compiling, and affects only the ability to launch host platform
6160 executables on the build platform using an emulation or API-enhancement
6161 environment such as Wine.  Failure to convert paths
6162 (@pxref{File Name Conversion Failure}) will cause a warning to be issued, but
6163 rarely causes the build to fail---and should have no affect on the compiled
6164 products, once installed properly on the host platform.  For more information,
6165 @pxref{Cross compiling}.
6167 However, file name conversion may also occur in another scenario: when using a
6168 Unix emulation system on Windows (such as Cygwin or MSYS), combined with a
6169 native Windows compiler such as MinGW or MSVC.  Only a limited set of such
6170 scenarios are currently supported; in other cases file name conversion is
6171 skipped.  The lack of file name conversion usually means that uninstalled
6172 executables can't be launched, but only rarely causes the build to fail
6173 (@pxref{File Name Conversion Failure}).
6175 libtool supports file name conversion in the following scenarios:
6177 @multitable @columnfractions .25 .25 .5
6178 @headitem build platform @tab host platform @tab Notes
6179 @item MinGW (MSYS) @tab MinGW (Windows)
6180 @tab @pxref{Native MinGW File Name Conversion}
6182 @item Cygwin @tab MinGW (Windows)
6183 @tab @pxref{Cygwin/Windows File Name Conversion}
6185 @item Unix + Wine @tab MinGW (Windows)
6186 @tab Requires Wine. @xref{Unix/Windows File Name Conversion}.
6188 @item MinGW (MSYS) @tab Cygwin
6189 @tab Requires @env{LT_CYGPATH}. @xref{LT_CYGPATH}. Provided for testing
6190 purposes only.
6192 @item Unix + Wine @tab Cygwin
6193 @tab Requires both Wine and @env{LT_CYGPATH}, but does not yet work with
6194 Cygwin 1.7.7 and Wine-1.2.
6195 @xref{Unix/Windows File Name Conversion}, and @ref{LT_CYGPATH}.
6196 @end multitable
6198 @menu
6199 * File Name Conversion Failure::  What happens when file name conversion fails
6200 * Native MinGW File Name Conversion::  MSYS file name conversion idiosyncrasies
6201 * Cygwin/Windows File Name Conversion::  Using @command{cygpath} to convert Cygwin file names
6202 * Unix/Windows File Name Conversion::  Using Wine to convert Unix paths
6203 * LT_CYGPATH::                  Invoking @command{cygpath} from other environments
6204 * Cygwin to MinGW Cross::       Other notes concerning MinGW cross
6205 @end menu
6207 @node File Name Conversion Failure
6208 @subsubsection File Name Conversion Failure
6209 @cindex File Name Conversion - Failure
6210 @cindex Path Conversion - Failure
6212 In most cases, file name conversion is not needed or attempted.  However, when
6213 libtool detects that a specific combination of build and host platform does
6214 require file name conversion, it is possible that the conversion may fail.
6215 In these cases, you may see a warning such as the following:
6217 @example
6218 Could not determine the host file name corresponding to
6219   `... a file name ...'
6220 Continuing, but uninstalled executables may not work.
6221 @end example
6223 @noindent
6226 @example
6227 Could not determine the host path corresponding to
6228   `... a path ...'
6229 Continuing, but uninstalled executables may not work.
6230 @end example
6232 @noindent
6233 This should not cause the build to fail.  At worst, it means that the wrapper
6234 executable will specify file names or paths appropriate for the build platform.
6235 Since those are not appropriate for the host platform, the uninstalled
6236 executables would not operate correctly, even when the wrapper executable is
6237 launched via the appropriate emulation or API-enhancement (e.g. Wine).  Simply
6238 install the executables on the host platform, and execute them there.
6240 @node Native MinGW File Name Conversion
6241 @subsubsection Native MinGW File Name Conversion
6242 @cindex File Name Conversion - MinGW
6243 @cindex Path Conversion - MinGW
6244 @cindex MSYS
6246 MSYS is a Unix emulation environment for Windows, and is specifically designed
6247 such that in normal usage it @emph{pretends} to be MinGW or native Windows,
6248 but understands Unix-style file names and paths, and supports standard Unix
6249 tools and shells.  Thus, ``native'' MinGW builds are actually an odd sort of
6250 cross-compile, from an MSYS Unix emulation environment ``pretending'' to be
6251 MinGW, to actual native Windows.
6253 When an MSYS shell launches a native Windows executable (as opposed to other
6254 @emph{MSYS} executables), it uses a system of heuristics to detect any
6255 command-line arguments that contain file names or paths.  It automatically
6256 converts these file names from the MSYS (Unix-like) format, to the
6257 corresponding Windows file name, before launching the executable.  However,
6258 this auto-conversion facility is only available when using the MSYS runtime
6259 library.  The wrapper executable itself is a MinGW application (that is, it
6260 does not use the MSYS runtime library).  The wrapper executable must set
6261 @env{PATH} to, and call @code{_spawnv} with, values that have already been
6262 converted from MSYS format to Windows.  Thus, when libtool writes the source
6263 code for the wrapper executable, it must manually convert MSYS paths to
6264 Windows format, so that the Windows values can be hard-coded into the wrapper
6265 executable.
6267 @node Cygwin/Windows File Name Conversion
6268 @subsubsection Cygwin/Windows File Name Conversion
6269 @cindex File Name Conversion - Cygwin to Windows
6270 @cindex Path Conversion - Cygwin to Windows
6272 Cygwin provides a Unix emulation environment for Windows.  As part of that
6273 emulation, it provides a file system mapping that presents the Windows file
6274 system in a Unix-compatible manner.  Cygwin also provides a utility
6275 @command{cygpath} that can be used to convert file names and paths between
6276 the two representations.  In a correctly configured Cygwin installation,
6277 @command{cygpath} is always present, and is in the @env{PATH}.
6279 Libtool uses @command{cygpath} to convert from Cygwin (Unix-style) file names
6280 and paths to Windows format when the build platform is Cygwin and the host
6281 platform is MinGW.
6283 When the host platform is Cygwin, but the build platform is MSYS or some Unix
6284 system, libtool also uses @command{cygpath} to convert from Windows to Cygwin
6285 format (after first converting from the build platform format to Windows format;
6286 @xref{Native MinGW File Name Conversion}, and
6287 @ref{Unix/Windows File Name Conversion}.)  Because the build platform is not
6288 Cygwin, @command{cygpath} is not (and should not be) in the @env{PATH}.
6289 Therefore, in this configuration the environment variable @env{LT_CYGPATH} is
6290 required. @xref{LT_CYGPATH}.
6292 @node Unix/Windows File Name Conversion
6293 @subsubsection Unix/Windows File Name Conversion
6294 @cindex File Name Conversion - Unix to Windows
6295 @cindex Path Conversion - Unix to Windows
6298 @uref{http://www.winehq.org/, Wine} provides an interpretation environment for
6299 some Unix platforms where Windows applications can be executed.  It provides
6300 a mapping between the Unix file system and a virtual Windows file system used
6301 by the Windows programs.  For the file name conversion to work, Wine must be
6302 installed and properly configured on the build platform, and the
6303 @command{winepath} application must be in the build platform's @env{PATH}.  In
6304 addition, on 32bit GNU/Linux it is usually helpful if the binfmt extension is
6305 enabled.
6307 @node LT_CYGPATH
6308 @subsubsection LT_CYGPATH
6309 @cindex LT_CYGPATH
6311 For some cross-compile configurations (where the host platform is Cygwin), the
6312 @command{cygpath} program is used to convert file names from the build platform
6313 notation to the Cygwin form (technically, this conversion is from Windows
6314 notation to Cygwin notation; the conversion from the build platform format
6315 to Windows notation is performed via other means).  However, because the
6316 @command{cygpath} program is not (and should not be) in the @env{PATH} on
6317 the build platform, @env{LT_CYGPATH} must specify the full build platform
6318 file name (that is, the full Unix or MSYS file name) of the @command{cygpath}
6319 program.
6321 The reason @command{cygpath} should not be in the build platform @env{PATH} is
6322 twofold: first, @command{cygpath} is usually installed in the same directory as
6323 many other Cygwin executables, such as @command{sed}, @command{cp}, etc.  If
6324 the build platform environment had this directory in its @env{PATH}, then these
6325 Cygwin versions of common Unix utilities might be used in preference to the
6326 ones provided by the build platform itself, with deleterious effects.  Second,
6327 especially when Cygwin-1.7 or later is used, multiple Cygwin installations can
6328 coexist within the same Windows instance.  Each installation will have separate
6329 ``mount tables'' specified in @file{@var{CYGROOT-N}/etc/fstab}.  These
6330 @dfn{mount tables} control how that instance of Cygwin will map Windows file
6331 names and paths to Cygwin form.  Each installation's @command{cygpath} utility
6332 automatically deduces the appropriate @file{/etc/fstab} file.  Since each
6333 @file{@var{CYGROOT-N}/etc/fstab} mount table may specify different mappings, it
6334 matters what @command{cygpath} is used.
6336 Note that @command{cygpath} is a Cygwin application; to execute this tool from
6337 Unix requires a working and properly configured Wine installation, as well
6338 as enabling the GNU/Linux @code{binfmt} extension.  Furthermore, the Cygwin
6339 @command{setup.exe} tool should have been used, via Wine, to properly install
6340 Cygwin into the Wine file system (and registry).
6342 Unfortunately, Wine support for Cygwin is intermittent.  Recent releases of
6343 Cygwin (1.7 and above) appear to require more Windows API support than Wine
6344 provides (as of Wine version 1.2); most Cygwin applications fail to execute.
6345 This includes @command{cygpath} itself.  Hence, it is best @emph{not} to use
6346 the LT_CYGPATH machinery in libtool when performing Unix to Cygwin
6347 cross-compiles.  Similarly, it is best @emph{not} to enable the GNU/Linux binfmt
6348 support in this configuration, because while Wine will fail to execute the
6349 compiled Cygwin applications, it will still exit with status zero.  This tends
6350 to confuse build systems and test suites (including libtool's own testsuite,
6351 resulting in spurious reported failures).  Wine support for the older
6352 Cygwin-1.5 series appears satisfactory, but the Cygwin team no longer supports
6353 Cygwin-1.5.  It is hoped that Wine will eventually be improved such that
6354 Cygwin-1.7 will again operate correctly under Wine.  Until then, libtool will
6355 report warnings as described in @pxref{File Name Conversion Failure} in these
6356 scenarios.
6358 However, @env{LT_CYGPATH} is also used for the MSYS to Cygwin cross compile
6359 scenario, and operates as expected.
6361 @node Cygwin to MinGW Cross
6362 @subsubsection Cygwin to MinGW Cross
6363 @cindex Cygwin to MinGW Cross
6365 There are actually three different scenarios that could all legitimately be
6366 called a ``Cygwin to MinGW'' cross compile.  The current (and standard)
6367 definition is when there is a compiler that produces native Windows libraries
6368 and applications, but which itself is a Cygwin application, just as would be
6369 expected in any other cross compile setup.
6371 However, historically there were two other definitions, which we will refer
6372 to as the @emph{fake} one, and the @emph{lying} one.
6374 In the @emph{fake} Cygwin to MinGW cross compile case, you actually use a
6375 native MinGW compiler, but you do so from within a Cygwin environment:
6377 @example
6378 @kbd{export PATH="/c/MinGW/bin:$@{PATH@}"}
6379 @kbd{configure --build=i686-pc-cygwin \
6380         --host=mingw32 \
6381         NM=/c/MinGW/bin/nm.exe}
6382 @end example
6384 In this way, the build system ``knows'' that you are cross compiling, and the
6385 file name conversion logic will be used.  However, because the tools
6386 (@command{mingw32-gcc}, @command{nm}, @command{ar}) used are actually native
6387 Windows applications, they will not understand any Cygwin (that is, Unix-like)
6388 absolute file names passed as command line arguments (and, unlike MSYS, Cygwin
6389 does not automatically convert such arguments).  However, so long as only
6390 relative file names are used in the build system, and non-Windows-supported
6391 Unix idioms such as symlinks and mount points are avoided, this scenario should
6392 work.
6394 If you must use absolute file names, you will have to force Libtool to convert
6395 file names for the toolchain in this case, by doing the following before you
6396 run configure:
6398 @example
6399 @kbd{export lt_cv_to_tool_file_cmd=func_convert_file_cygwin_to_w32}
6400 @end example
6401 @cindex lt_cv_to_tool_file_cmd
6402 @cindex func_convert_file_cygwin_to_w32
6404 In the @emph{lying} Cygwin to MinGW cross compile case, you lie to the
6405 build system:
6407 @example
6408 @kbd{export PATH="/c/MinGW/bin:$@{PATH@}"}
6409 @kbd{configure --build=i686-pc-mingw32 \
6410         --host=i686-pc-mingw32 \
6411         --disable-dependency-tracking}
6412 @end example
6414 @noindent
6415 and claim that the build platform is MinGW, even though you are actually
6416 running under @emph{Cygwin} and not MinGW.  In this case, libtool does
6417 @emph{not} know that you are performing a cross compile, and thinks instead
6418 that you are performing a native MinGW build.  However, as described in
6419 (@pxref{Native MinGW File Name Conversion}), that scenario triggers an ``MSYS
6420 to Windows'' file name conversion.  This, of course, is the wrong conversion
6421 since we are actually running under Cygwin.  Also, the toolchain is expecting
6422 Windows file names (not Cygwin) but unless told so Libtool will feed Cygwin
6423 file names to the toolchain in this case.  To force the correct file name
6424 conversions in this situation, you should do the following @emph{before}
6425 running configure:
6427 @example
6428 @kbd{export lt_cv_to_host_file_cmd=func_convert_file_cygwin_to_w32}
6429 @kbd{export lt_cv_to_tool_file_cmd=func_convert_file_cygwin_to_w32}
6430 @end example
6431 @cindex lt_cv_to_host_file_cmd
6432 @cindex lt_cv_to_tool_file_cmd
6433 @cindex func_convert_file_cygwin_to_w32
6435 Note that this relies on internal implementation details of libtool, and
6436 is subject to change.  Also, @code{--disable-dependency-tracking} is required,
6437 because otherwise the MinGW GCC will generate dependency files that contain
6438 Windows file names.  This, in turn, will confuse the Cygwin @command{make}
6439 program, which does not accept Windows file names:
6441 @example
6442 Makefile:1: *** target pattern contains no `%'.  Stop.
6443 @end example
6445 There have also always been a number of other details required for the
6446 @emph{lying} case to operate correctly, such as the use of so-called
6447 @dfn{identity mounts}:
6449 @example
6450 # @var{cygwin-root}/etc/fstab
6451 D:/foo    /foo     some_fs binary 0 0
6452 D:/bar    /bar     some_fs binary 0 0
6453 E:/grill  /grill   some_fs binary 0 0
6454 @end example
6456 In this way, top-level directories of each drive are available using
6457 identical names within Cygwin.
6459 Note that you also need to ensure that the standard Unix directories
6460 (like @file{/bin}, @file{/lib}, @file{/usr}, @file{/etc}) appear in the root
6461 of a drive.  This means that you must install Cygwin itself into the @file{C:/}
6462 root directory (or @file{D:/}, or @file{E:/}, etc)---instead of the
6463 recommended installation into @file{C:/cygwin/}.  In addition, all file names
6464 used in the build system must be relative, symlinks should not be used within
6465 the source or build directory trees, and all @option{-M*} options to
6466 @command{gcc} except @option{-MMD} must be avoided.
6468 This is quite a fragile setup, but it has been in historical use, and so is
6469 documented here.
6471 @node Windows DLLs
6472 @subsection Windows DLLs
6473 @cindex Windows DLLs
6475 This topic describes a couple of ways to portably create Windows Dynamic
6476 Link Libraries (DLLs).  Libtool knows how to create DLLs using GNU tools
6477 and using Microsoft tools.
6479 A typical library has a ``hidden'' implementation with an interface
6480 described in a header file.  On just about every system, the interface
6481 could be something like this:
6483 Example @file{foo.h}:
6485 @example
6486 #ifndef FOO_H
6487 #define FOO_H
6489 int one (void);
6490 int two (void);
6491 extern int three;
6493 #endif /* FOO_H */
6494 @end example
6496 @noindent
6497 And the implementation could be something like this:
6499 Example @file{foo.c}:
6501 @example
6502 #include "foo.h"
6504 int one (void)
6506   return 1;
6509 int two (void)
6511   return three - one ();
6514 int three = 3;
6515 @end example
6517 When using contemporary GNU tools to create the Windows DLL, the above
6518 code will work there too, thanks to its auto-import/auto-export
6519 features.  But that is not the case when using older GNU tools or perhaps
6520 more interestingly when using proprietary tools.  In those cases the code
6521 will need additional decorations on the interface symbols with
6522 @code{__declspec(dllimport)} and @code{__declspec(dllexport)} depending
6523 on whether the library is built or it's consumed and how it's built and
6524 consumed.  However, it should be noted that it would have worked also
6525 with Microsoft tools, if only the variable @code{three} hadn't been
6526 there, due to the fact the Microsoft tools will automatically import
6527 functions (but sadly not variables) and Libtool will automatically export
6528 non-static symbols as described next.
6530 With Microsoft tools, Libtool digs through the object files that make up
6531 the library, looking for non-static symbols to automatically export.
6532 I.e., Libtool with Microsoft tools tries to mimic the auto-export feature
6533 of contemporary GNU tools.  It should be noted that the GNU auto-export
6534 feature is turned off when an explicit @code{__declspec(dllexport)} is
6535 seen.  The GNU tools do this to not make more symbols visible for projects
6536 that have already taken the trouble to decorate symbols.  There is no
6537 similar way to limit what symbols are visible in the code when Libtool
6538 is using Microsoft tools.  In order to limit symbol visibility in that
6539 case you need to use one of the options @option{-export-symbols} or
6540 @option{-export-symbols-regex}.
6542 No matching help with auto-import is provided by Libtool, which is why
6543 variables must be decorated to import them from a DLL for everything but
6544 contemporary GNU tools.  As stated above, functions are automatically
6545 imported by both contemporary GNU tools and Microsoft tools, but for
6546 other proprietary tools the auto-import status of functions is unknown.
6548 When the objects that form the library are built, there are generally
6549 two copies built for each object.  One copy is used when linking the DLL
6550 and one copy is used for the static library.  On Windows systems, a pair
6551 of defines are commonly used to discriminate how the interface symbols
6552 should be decorated.  The first define is @samp{-DDLL_EXPORT}, which is
6553 automatically provided by Libtool when @command{libtool} builds the copy
6554 of the object that is destined for the DLL.  The second define is
6555 @samp{-DLIBFOO_BUILD} (or similar), which is often added by the package
6556 providing the library and is used when building the library, but not
6557 when consuming the library.
6559 However, the matching double compile is not performed when consuming
6560 libraries.  It is therefore not possible to reliably distinguish if the
6561 consumer is importing from a DLL or if it is going to use a static
6562 library.
6564 With contemporary GNU tools, auto-import often saves the day, but see
6565 the GNU ld documentation and its @option{--enable-auto-import} option
6566 for some corner cases when it does not
6567 (@pxref{Options, @option{--enable-auto-import}, Options specific to
6568 i386 PE targets, ld, Using ld@comma{} the GNU linker}).
6570 With Microsoft tools you typically get away with always compiling the
6571 code such that variables are expected to be imported from a DLL and
6572 functions are expected to be found in a static library.  The tools will
6573 then automatically import the function from a DLL if that is where they
6574 are found.  If the variables are not imported from a DLL as expected, but
6575 are found in a static library that is otherwise pulled in by some
6576 function, the linker will issue a warning (LNK4217) that a locally
6577 defined symbol is imported, but it still works.  In other words, this
6578 scheme will not work to only consume variables from a library.  There is
6579 also a price connected to this liberal use of imports in that an extra
6580 indirection is introduced when you are consuming the static version of
6581 the library.  That extra indirection is unavoidable when the DLL is
6582 consumed, but it is not needed when consuming the static library.
6584 For older GNU tools and other proprietary tools there is no generic way
6585 to make it possible to consume either of the DLL or the static library
6586 without user intervention, the tools need to be told what is intended.
6587 One common assumption is that if a DLL is being built (@samp{DLL_EXPORT}
6588 is defined) then that DLL is going to consume any dependent libraries as
6589 DLLs.  If that assumption is made everywhere, it is possible to select
6590 how an end-user application is consuming libraries by adding a single
6591 flag @samp{-DDLL_EXPORT} when a DLL build is required.  This is of course
6592 an all or nothing deal, either everything as DLLs or everything as static
6593 libraries.
6595 To sum up the above, the header file of the foo library needs to be
6596 changed into something like this:
6598 Modified @file{foo.h}:
6600 @example
6601 #ifndef FOO_H
6602 #define FOO_H
6604 #if defined _WIN32 && !defined __GNUC__
6605 # ifdef LIBFOO_BUILD
6606 #  ifdef DLL_EXPORT
6607 #   define LIBFOO_SCOPE            __declspec (dllexport)
6608 #   define LIBFOO_SCOPE_VAR extern __declspec (dllexport)
6609 #  endif
6610 # elif defined _MSC_VER
6611 #  define LIBFOO_SCOPE
6612 #  define LIBFOO_SCOPE_VAR  extern __declspec (dllimport)
6613 # elif defined DLL_EXPORT
6614 #  define LIBFOO_SCOPE             __declspec (dllimport)
6615 #  define LIBFOO_SCOPE_VAR  extern __declspec (dllimport)
6616 # endif
6617 #endif
6618 #ifndef LIBFOO_SCOPE
6619 # define LIBFOO_SCOPE
6620 # define LIBFOO_SCOPE_VAR extern
6621 #endif
6623 LIBFOO_SCOPE     int one (void);
6624 LIBFOO_SCOPE     int two (void);
6625 LIBFOO_SCOPE_VAR int three;
6627 #endif /* FOO_H */
6628 @end example
6630 When the targets are limited to contemporary GNU tools and Microsoft
6631 tools, the above can be simplified to the following:
6633 Simplified @file{foo.h}:
6635 @example
6636 #ifndef FOO_H
6637 #define FOO_H
6639 #if defined _WIN32 && !defined __GNUC__ && !defined LIBFOO_BUILD
6640 # define LIBFOO_SCOPE_VAR extern __declspec (dllimport)
6641 #else
6642 # define LIBFOO_SCOPE_VAR extern
6643 #endif
6645 int one (void);
6646 int two (void);
6647 LIBFOO_SCOPE_VAR int three;
6649 #endif /* FOO_H */
6650 @end example
6652 This last simplified version can of course only work when Libtool is
6653 used to build the DLL, as no symbols would be exported otherwise (i.e.,
6654 when using Microsoft tools).
6656 It should be noted that there are various projects that attempt to relax
6657 these requirements by various low level tricks, but they are not
6658 discussed here.
6659 Examples are
6660 @uref{http://alain.frisch.fr/@/flexdll.html, FlexDLL} and
6661 @uref{http://edll.sourceforge.net/, edll}.
6664 @node libtool script contents
6665 @section @code{libtool} script contents
6666 @cindex implementation of libtool
6667 @cindex libtool implementation
6669 Since version 1.4, the @code{libtool} script is generated by
6670 @code{configure} (@pxref{Configuring}).  In earlier versions,
6671 @code{configure} achieved this by calling a helper script called
6672 @file{ltconfig}.  From libtool version 0.7 to 1.0, this script
6673 simply set shell variables, then sourced the libtool backend,
6674 @code{ltmain.sh}.  @code{ltconfig} from libtool version 1.1 through 1.3
6675 inlined the contents of @code{ltmain.sh} into the generated
6676 @code{libtool}, which improved performance on many systems.  The tests
6677 that @file{ltconfig} used to perform are now kept in @file{libtool.m4}
6678 where they can be written using Autoconf.  This has the runtime
6679 performance benefits of inlined @code{ltmain.sh}, @emph{and} improves
6680 the build time a little while considerably easing the amount of raw
6681 shell code that used to need maintaining.
6683 The convention used for naming variables that hold shell commands for
6684 delayed evaluation, is to use the suffix @code{_cmd} where a single
6685 line of valid shell script is needed, and the suffix @code{_cmds} where
6686 multiple lines of shell script @strong{may} be delayed for later
6687 evaluation.  By convention, @code{_cmds} variables delimit the
6688 evaluation units with the @code{~} character where necessary.
6690 Here is a listing of each of the configuration variables, and how they
6691 are used within @code{ltmain.sh} (@pxref{Configuring}):
6693 @defvar AR
6694 The name of the system library archiver.
6695 @end defvar
6697 @defvar CC
6698 The name of the compiler used to configure libtool.  This will always
6699 contain the compiler for the current language (@pxref{Tags}).
6700 @end defvar
6702 @defvar ECHO
6703 An @command{echo} program that does not interpret backslashes as an
6704 escape character.  It may be given only one argument, so due quoting
6705 is necessary.
6706 @end defvar
6708 @defvar LD
6709 The name of the linker that libtool should use internally for reloadable
6710 linking and possibly shared libraries.
6711 @end defvar
6713 @defvar LTCC
6714 @defvarx LTCFLAGS
6715 The name of the C compiler and C compiler flags used to configure
6716 libtool.
6717 @end defvar
6719 @defvar NM
6720 The name of a BSD- or MS-compatible program that produces listings of
6721 global symbols.
6722 For BSD @command{nm}, the symbols should be in one the following formats:
6724 @example
6725 @var{address} C @var{global-variable-name}
6726 @var{address} D @var{global-variable-name}
6727 @var{address} T @var{global-function-name}
6728 @end example
6730 For MS @command{dumpbin}, the symbols should be in one of the following
6731 formats:
6733 @example
6734 @var{counter} @var{size}    UNDEF    notype       External     | @var{global-var}
6735 @var{counter} @var{address} @var{section}  notype       External     | @var{global-var}
6736 @var{counter} @var{address} @var{section}  notype ()    External     | @var{global-func}
6737 @end example
6739 The @var{size} of the global variables are not zero and the @var{section}
6740 of the global functions are not "UNDEF". Symbols in "pick any" sections
6741 ("pick any" appears in the section header) are not global either.
6742 @end defvar
6744 @defvar RANLIB
6745 Set to the name of the @command{ranlib} program, if any.
6746 @end defvar
6748 @defvar allow_undefined_flag
6749 The flag that is used by @samp{archive_cmds} to declare that
6750 there will be unresolved symbols in the resulting shared library.
6751 Empty, if no such flag is required.  Set to @samp{unsupported} if there
6752 is no way to generate a shared library with references to symbols that
6753 aren't defined in that library.
6754 @end defvar
6756 @defvar always_export_symbols
6757 Whether libtool should automatically generate a list of exported symbols
6758 using @code{export_symbols_cmds} before linking an archive.
6759 Set to @samp{yes} or @samp{no}.  Default is @samp{no}.
6760 @end defvar
6762 @defvar archive_cmds
6763 @defvarx archive_expsym_cmds
6764 @defvarx old_archive_cmds
6765 Commands used to create shared libraries, shared libraries with
6766 @option{-export-symbols} and static libraries, respectively.
6767 @end defvar
6769 @defvar archiver_list_spec
6770 Specify filename containing input files for @code{AR}.
6771 @end defvar
6773 @defvar old_archive_from_new_cmds
6774 If the shared library depends on a static library,
6775 @samp{old_archive_from_new_cmds} contains the commands used to create that
6776 static library.  If this variable is not empty, @samp{old_archive_cmds} is
6777 not used.
6778 @end defvar
6780 @defvar old_archive_from_expsyms_cmds
6781 If a static library must be created from the export symbol list to
6782 correctly link with a shared library, @samp{old_archive_from_expsyms_cmds}
6783 contains the commands needed to create that static library.  When these
6784 commands are executed, the variable @code{soname} contains the name of the
6785 shared library in question, and the @samp{$objdir/$newlib} contains the
6786 path of the static library these commands should build.  After executing
6787 these commands, libtool will proceed to link against @samp{$objdir/$newlib}
6788 instead of @code{soname}.
6789 @end defvar
6791 @defvar lock_old_archive_extraction
6792 Set to @samp{yes} if the extraction of a static library requires locking
6793 the library file.  This is required on Darwin.
6794 @end defvar
6796 @defvar build
6797 @defvarx build_alias
6798 @defvarx build_os
6799 Set to the specified and canonical names of the system that libtool was
6800 built on.
6801 @end defvar
6803 @defvar build_libtool_libs
6804 Whether libtool should build shared libraries on this system.  Set to
6805 @samp{yes} or @samp{no}.
6806 @end defvar
6808 @defvar build_old_libs
6809 Whether libtool should build static libraries on this system.  Set to
6810 @samp{yes} or @samp{no}.
6811 @end defvar
6813 @defvar compiler_c_o
6814 Whether the compiler supports the @option{-c} and @option{-o} options
6815 simultaneously.  Set to @samp{yes} or @samp{no}.
6816 @end defvar
6818 @defvar compiler_needs_object
6819 Whether the compiler has to see an object listed on the command line in
6820 order to successfully invoke the linker.  If @samp{no}, then a set of
6821 convenience archives or a set of object file names can be passed via
6822 linker-specific options or linker scripts.
6823 @end defvar
6825 @defvar dlopen_support
6826 Whether @code{dlopen} is supported on the platform.
6827 Set to @samp{yes} or @samp{no}.
6828 @end defvar
6830 @defvar dlopen_self
6831 Whether it is possible to @code{dlopen} the executable itself.
6832 Set to @samp{yes} or @samp{no}.
6833 @end defvar
6835 @defvar dlopen_self_static
6836 Whether it is possible to @code{dlopen} the executable itself, when it
6837 is linked statically (@option{-all-static}).  Set to @samp{yes} or
6838 @samp{no}.
6839 @end defvar
6841 @defvar exclude_expsyms
6842 List of symbols that should not be listed in the preloaded symbols.
6843 @end defvar
6845 @defvar export_dynamic_flag_spec
6846 Compiler link flag that allows a dlopened shared library to reference
6847 symbols that are defined in the program.
6848 @end defvar
6850 @defvar export_symbols_cmds
6851 Commands to extract exported symbols from @code{libobjs} to the
6852 file @code{export_symbols}.
6853 @end defvar
6855 @defvar extract_expsyms_cmds
6856 Commands to extract the exported symbols list from a shared library.
6857 These commands are executed if there is no file @samp{$objdir/$soname-def},
6858 and should write the names of the exported symbols to that file, for
6859 the use of @samp{old_archive_from_expsyms_cmds}.
6860 @end defvar
6862 @defvar fast_install
6863 Determines whether libtool will privilege the installer or the
6864 developer.  The assumption is that installers will seldom run programs
6865 in the build tree, and the developer will seldom install.  This is only
6866 meaningful on platforms where @code{shlibpath_overrides_runpath} is
6867 not @samp{yes}, so @code{fast_install} will be set to @samp{needless} in
6868 this case.  If @code{fast_install} set to @samp{yes}, libtool will create
6869 programs that search for installed libraries, and, if a program is run
6870 in the build tree, a new copy will be linked on-demand to use the
6871 yet-to-be-installed libraries.  If set to @samp{no}, libtool will create
6872 programs that use the yet-to-be-installed libraries, and will link
6873 a new copy of the program at install time.  The default value is
6874 @samp{yes} or @samp{needless}, depending on platform and configuration
6875 flags, and it can be turned from @samp{yes} to @samp{no} with the
6876 configure flag @option{--disable-fast-install}.
6878 On some systems, the linker always hardcodes paths to dependent libraries
6879 into the output.  In this case, @code{fast_install} is never set to @samp{yes},
6880 and relinking at install time is triggered.  This also means that @env{DESTDIR}
6881 installation does not work as expected.
6882 @end defvar
6884 @defvar file_magic_glob
6885 How to find potential files when @code{deplibs_check_method} is
6886 @samp{file_magic}. @code{file_magic_glob} is a @code{sed} expression,
6887 and the @code{sed} instance is fed potential file names that are
6888 transformed by the @code{file_magic_glob} expression. Useful when the
6889 shell does not support the shell option @code{nocaseglob}, making
6890 @code{want_nocaseglob} inappropriate. Normally disabled (i.e.
6891 @code{file_magic_glob} is empty).
6892 @end defvar
6894 @defvar finish_cmds
6895 Commands to tell the dynamic linker how to find shared libraries in a
6896 specific directory.
6897 @end defvar
6899 @defvar finish_eval
6900 Same as @code{finish_cmds}, except the commands are not displayed.
6901 @end defvar
6903 @defvar global_symbol_pipe
6904 A pipeline that takes the output of @code{NM}, and produces a listing of
6905 raw symbols followed by their C names.  For example:
6907 @example
6908 $ @kbd{eval "$NM progname | $global_symbol_pipe"}
6909 D @var{symbol1} @var{C-symbol1}
6910 T @var{symbol2} @var{C-symbol2}
6911 C @var{symbol3} @var{C-symbol3}
6912 @dots{}
6914 @end example
6916 The first column contains the symbol type (used to tell data from code)
6917 but its meaning is system dependent.
6918 @end defvar
6920 @defvar global_symbol_to_cdecl
6921 A pipeline that translates the output of @code{global_symbol_pipe} into
6922 proper C declarations.  Since some platforms, such as HP/UX, have
6923 linkers that differentiate code from data, data symbols are declared
6924 as data, and code symbols are declared as functions.
6925 @end defvar
6927 @defvar hardcode_action
6928 Either @samp{immediate} or @samp{relink}, depending on whether shared
6929 library paths can be hardcoded into executables before they are installed,
6930 or if they need to be relinked.
6931 @end defvar
6933 @defvar hardcode_direct
6934 Set to @samp{yes} or @samp{no}, depending on whether the linker
6935 hardcodes directories if a library is directly specified on the command
6936 line (such as @samp{@var{dir}/lib@var{name}.a}) when
6937 @code{hardcode_libdir_flag_spec} is specified.
6938 @end defvar
6940 @defvar hardcode_direct_absolute
6941 Some architectures hardcode "absolute" library directories that cannot
6942 be overridden by @code{shlibpath_var} when @code{hardcode_direct} is
6943 @samp{yes}.  In that case set @code{hardcode_direct_absolute} to
6944 @samp{yes}, or otherwise @samp{no}.
6945 @end defvar
6947 @defvar hardcode_into_libs
6948 Whether the platform supports hardcoding of run-paths into libraries.
6949 If enabled, linking of programs will be much simpler but libraries will
6950 need to be relinked during installation.  Set to @samp{yes} or @samp{no}.
6951 @end defvar
6953 @defvar hardcode_libdir_flag_spec
6954 Flag to hardcode a @code{libdir} variable into a binary, so that the
6955 dynamic linker searches @code{libdir} for shared libraries at runtime.
6956 If it is empty, libtool will try to use some other hardcoding mechanism.
6957 @end defvar
6959 @defvar hardcode_libdir_separator
6960 If the compiler only accepts a single @code{hardcode_libdir_flag}, then
6961 this variable contains the string that should separate multiple
6962 arguments to that flag.
6963 @end defvar
6965 @defvar hardcode_minus_L
6966 Set to @samp{yes} or @samp{no}, depending on whether the linker
6967 hardcodes directories specified by @option{-L} flags into the resulting
6968 executable when @code{hardcode_libdir_flag_spec} is specified.
6969 @end defvar
6971 @defvar hardcode_shlibpath_var
6972 Set to @samp{yes} or @samp{no}, depending on whether the linker
6973 hardcodes directories by writing the contents of @samp{$shlibpath_var}
6974 into the resulting executable when @code{hardcode_libdir_flag_spec} is
6975 specified.  Set to @samp{unsupported} if directories specified by
6976 @samp{$shlibpath_var} are searched at run time, but not at link time.
6977 @end defvar
6979 @defvar host
6980 @defvarx host_alias
6981 @defvarx host_os
6982 Set to the specified and canonical names of the system that libtool was
6983 configured for.
6984 @end defvar
6986 @defvar include_expsyms
6987 List of symbols that must always be exported when using @code{export_symbols}.
6988 @end defvar
6990 @defvar inherit_rpath
6991 Whether the linker adds runtime paths of dependency libraries to the
6992 runtime path list, requiring libtool to relink the output when installing.
6993 Set to @samp{yes} or @samp{no}.  Default is @samp{no}.
6994 @end defvar
6996 @defvar install_override_mode
6997 Permission mode override for installation of shared libraries.  If the
6998 runtime linker fails to load libraries with wrong permissions, then it
6999 may fail to execute programs that are needed during installation,
7000 because these need the library that has just been installed.  In this
7001 case, it is necessary to pass the mode to @command{install} with
7002 @option{-m @var{install_override_mode}}.
7003 @end defvar
7005 @defvar libext
7006 The standard old archive suffix (normally @samp{a}).
7007 @end defvar
7009 @defvar libname_spec
7010 The format of a library name prefix.  On all Unix systems, static
7011 libraries are called @samp{lib@var{name}.a}, but on some systems (such
7012 as OS/2 or MS-DOS), the library is just called @samp{@var{name}.a}.
7013 @end defvar
7015 @defvar library_names_spec
7016 A list of shared library names.  The first is the name of the file,
7017 the rest are symbolic links to the file.  The name in the list is
7018 the file name that the linker finds when given @option{-l@var{name}}.
7019 @end defvar
7021 @defvar link_all_deplibs
7022 Whether libtool must link a program against all its dependency libraries.
7023 Set to @samp{yes} or @samp{no}.  Default is @samp{unknown}, which is
7024 a synonym for @samp{yes}.
7025 @end defvar
7027 @defvar link_static_flag
7028 Linker flag (passed through the C compiler) used to prevent dynamic
7029 linking.
7030 @end defvar
7032 @defvar macro_version
7033 @defvarx macro_revision
7034 The release and revision from which the libtool.m4 macros were
7035 taken.  This is used to ensure that macros and @code{ltmain.sh}
7036 correspond to the same Libtool version.
7037 @end defvar
7039 @defvar max_cmd_len
7040 The approximate longest command line that can be passed to @samp{$SHELL}
7041 without being truncated, as computed by @samp{LT_CMD_MAX_LEN}.
7042 @end defvar
7044 @defvar need_lib_prefix
7045 Whether we can @code{dlopen} modules without a @samp{lib} prefix.
7046 Set to @samp{yes} or @samp{no}.  By default, it is @samp{unknown}, which
7047 means the same as @samp{yes}, but documents that we are not really sure
7048 about it.  @samp{no} means that it is possible to @code{dlopen} a
7049 module without the @samp{lib} prefix.
7050 @end defvar
7052 @defvar need_version
7053 Whether versioning is required for libraries, i.e.@: whether the
7054 dynamic linker requires a version suffix for all libraries.
7055 Set to @samp{yes} or @samp{no}.  By default, it is @samp{unknown}, which
7056 means the same as @samp{yes}, but documents that we are not really sure
7057 about it.
7058 @end defvar
7060 @defvar need_locks
7061 Whether files must be locked to prevent conflicts when compiling
7062 simultaneously.  Set to @samp{yes} or @samp{no}.
7063 @end defvar
7065 @defvar nm_file_list_spec
7066 Specify filename containing input files for @code{NM}.
7067 @end defvar
7069 @defvar no_builtin_flag
7070 Compiler flag to disable builtin functions that conflict with declaring
7071 external global symbols as @code{char}.
7072 @end defvar
7074 @defvar no_undefined_flag
7075 The flag that is used by @samp{archive_cmds} to declare that
7076 there will be no unresolved symbols in the resulting shared library.
7077 Empty, if no such flag is required.
7078 @end defvar
7080 @defvar objdir
7081 The name of the directory that contains temporary libtool files.
7082 @end defvar
7084 @defvar objext
7085 The standard object file suffix (normally @samp{o}).
7086 @end defvar
7088 @defvar pic_flag
7089 Any additional compiler flags for building library object files.
7090 @end defvar
7092 @defvar postinstall_cmds
7093 @defvarx old_postinstall_cmds
7094 Commands run after installing a shared or static library, respectively.
7095 @end defvar
7097 @defvar postuninstall_cmds
7098 @defvarx old_postuninstall_cmds
7099 Commands run after uninstalling a shared or static library, respectively.
7100 @end defvar
7102 @defvar postlink_cmds
7103 Commands necessary for finishing linking programs. @code{postlink_cmds}
7104 are executed immediately after the program is linked.  Any occurrence of
7105 the string @code{@@OUTPUT@@} in @code{postlink_cmds} is replaced by the
7106 name of the created executable (i.e.@: not the wrapper, if a wrapper is
7107 generated) prior to execution.  Similarly, @code{@@TOOL_OUTPUT@@} is
7108 replaced by the toolchain format of @code{@@OUTPUT@@}.  Normally disabled
7109 (i.e.@: @code{postlink_cmds} empty).
7110 @end defvar
7112 @defvar reload_cmds
7113 @defvarx reload_flag
7114 Commands to create a reloadable object.  Set @code{reload_cmds} to
7115 @samp{false} on systems that cannot create reloadable objects.
7116 @end defvar
7118 @defvar runpath_var
7119 The environment variable that tells the linker what directories to
7120 hardcode in the resulting executable.
7121 @end defvar
7123 @defvar shlibpath_overrides_runpath
7124 Indicates whether it is possible to override the hard-coded library
7125 search path of a program with an environment variable.  If this is set
7126 to no, libtool may have to create two copies of a program in the build
7127 tree, one to be installed and one to be run in the build tree only.
7128 When each of these copies is created depends on the value of
7129 @code{fast_install}.  The default value is @samp{unknown}, which is
7130 equivalent to @samp{no}.
7131 @end defvar
7133 @defvar shlibpath_var
7134 The environment variable that tells the dynamic linker where to find
7135 shared libraries.
7136 @end defvar
7138 @defvar soname_spec
7139 The name coded into shared libraries, if different from the real name of
7140 the file.
7141 @end defvar
7143 @defvar striplib
7144 @defvarx old_striplib
7145 Command to strip a shared (@code{striplib}) or static (@code{old_striplib})
7146 library, respectively.  If these variables are empty, the strip flag
7147 in the install mode will be ignored for libraries (@pxref{Install mode}).
7148 @end defvar
7150 @defvar sys_lib_dlsearch_path_spec
7151 Expression to get the run-time system library search path.  Directories
7152 that appear in this list are never hard-coded into executables.
7153 @end defvar
7155 @defvar sys_lib_search_path_spec
7156 Expression to get the compile-time system library search path.  This
7157 variable is used by libtool when it has to test whether a certain
7158 library is shared or static.  The directories listed in
7159 @code{shlibpath_var} are automatically appended to this list, every time
7160 libtool runs (i.e., not at configuration time), because some linkers use
7161 this variable to extend the library search path.  Linker switches such
7162 as @option{-L} also augment the search path.
7163 @end defvar
7165 @defvar thread_safe_flag_spec
7166 Linker flag (passed through the C compiler) used to generate thread-safe
7167 libraries.
7168 @end defvar
7170 @defvar to_host_file_cmd
7171 If the toolchain is not native to the build platform (e.g.@: if you are using
7172 MSYS to drive the scripting, but are using the MinGW native Windows compiler)
7173 this variable describes how to convert file names from the format used by the
7174 build platform to the format used by host platform.  Normally set to
7175 @samp{func_convert_file_noop}, libtool will autodetect most cases where
7176 other values should be used.  On rare occasions, it may be necessary to override
7177 the autodetected value (@pxref{Cygwin to MinGW Cross}).
7178 @end defvar
7180 @defvar to_tool_file_cmd
7181 If the toolchain is not native to the build platform (e.g.@: if you are using
7182 some Unix to drive the scripting together with a Windows toolchain running
7183 in Wine) this variable describes how to convert file names from the format
7184 used by the build platform to the format used by the toolchain.  Normally set
7185 to @samp{func_convert_file_noop}.
7186 @end defvar
7188 @defvar version_type
7189 The library version numbering type.  One of @samp{libtool},
7190 @samp{freebsd-aout}, @samp{freebsd-elf}, @samp{irix}, @samp{linux},
7191 @samp{osf}, @samp{sunos}, @samp{windows}, or @samp{none}.
7192 @end defvar
7194 @defvar want_nocaseglob
7195 Find potential files using the shell option @code{nocaseglob}, when
7196 @code{deplibs_check_method} is @samp{file_magic}. Normally set to
7197 @samp{no}. Set to @samp{yes} to enable the @code{nocaseglob} shell
7198 option when looking for potential file names in a case-insensitive
7199 manner.
7200 @end defvar
7202 @defvar whole_archive_flag_spec
7203 Compiler flag to generate shared objects from convenience archives.
7204 @end defvar
7206 @defvar wl
7207 The C compiler flag that allows libtool to pass a flag directly to the
7208 linker.  Used as: @code{$@{wl@}@var{some-flag}}.
7209 @end defvar
7211 Variables ending in @samp{_cmds} or @samp{_eval} contain a
7212 @samp{~}-separated list of commands that are @code{eval}ed one after
7213 another.  If any of the commands return a nonzero exit status, libtool
7214 generally exits with an error message.
7216 Variables ending in @samp{_spec} are @code{eval}ed before being used by
7217 libtool.
7219 @node Cheap tricks
7220 @section Cheap tricks
7222 Here are a few tricks that you can use to make maintainership
7223 easier:
7225 @itemize @bullet
7226 @item
7227 When people report bugs, ask them to use the @option{--config},
7228 @option{--debug}, or @option{--features} flags, if you think they will help
7229 you.  These flags are there to help you get information directly, rather
7230 than having to trust second-hand observation.
7232 @item
7233 Rather than reconfiguring libtool every time I make a change to
7234 @code{ltmain.in}, I keep a permanent @code{libtool} script in my
7235 @env{PATH}, which sources @code{ltmain.in} directly.
7237 The following steps describe how to create such a script, where
7238 @code{/home/src/libtool} is the directory containing the libtool source
7239 tree, @code{/home/src/libtool/libtool} is a libtool script that has been
7240 configured for your platform, and @code{~/bin} is a directory in your
7241 @env{PATH}:
7243 @smallexample
7244 trick$ cd ~/bin
7245 trick$ sed 's%^\(macro_version=\).*$%\1@@VERSION@@%;
7246             s%^\(macro_revision=\).*$%\1@@package_revision@@%;
7247             /^# ltmain\.sh/q' /home/src/libtool/libtool > libtool
7248 trick$ echo '. /home/src/libtool/ltmain.in' >> libtool
7249 trick$ chmod +x libtool
7250 trick$ libtool --version
7251 ltmain.sh (GNU @@PACKAGE@@@@TIMESTAMP@@) @@VERSION@@
7253 Copyright (C) 2014 Free Software Foundation, Inc.
7254 This is free software; see the source for copying conditions.  There is NO
7255 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7256 trick$
7257 @end smallexample
7258 @end itemize
7260 The output of the final @samp{libtool --version} command shows that the
7261 @code{ltmain.in} script is being used directly.  Now, modify
7262 @code{~/bin/libtool} or @code{/home/src/libtool/ltmain.in} directly in
7263 order to test new changes without having to rerun @code{configure}.
7265 @node GNU Free Documentation License
7266 @appendix GNU Free Documentation License
7268 @cindex FDL, GNU Free Documentation License
7270 @include fdl.texi
7272 @page
7273 @node Combined Index
7274 @unnumbered Combined Index
7276 @printindex cp
7278 @bye