📄 libtool.texi
字号:
@enumerate 1@itemDownload Automake (version 1.2 or later) from your nearest GNU mirror,install it, and start using it.@itemLearn how to write @file{Makefile} rules by hand. They're sometimes complex,but if you're clever enough to write rules for compiling your oldlibraries, then you should be able to figure out new rules for libtoollibraries (hint: examine the @file{Makefile.in} in the @file{demo}subdirectory of the libtool distribution@dots{} note especially that itwas automatically generated from the @file{Makefile.am} by Automake).@end enumerate@node Using Automake@section Using Automake with libtool@vindex LTLIBRARIESLibtool library support is implemented under the @samp{LTLIBRARIES}primary.Here are some samples from the Automake @file{Makefile.am} in thelibtool distribution's @file{demo} subdirectory.First, to link a program against a libtool library, just use the@samp{program_LDADD} variable:@examplebin_PROGRAMS = hell hell.debug# Build hell from main.c and libhello.lahell_SOURCES = main.chell_LDADD = libhello.la# Create an easier-to-debug version of hell.hell_debug_SOURCES = main.chell_debug_LDADD = libhello.lahell_debug_LDFLAGS = -static@end exampleThe flags @samp{-dlopen} or @samp{-dlpreopen} (@pxref{Link mode}) wouldfit better in the @var{program_LDADD} variable. Unfortunately, GNUautomake, up to release 1.4, doesn't accept these flags in a@var{program_LDADD} variable, so you have the following alternatives:@itemize @bullet@itemadd them to @var{program_LDFLAGS}, and list the libraries in@var{program_DEPENDENCIES}, then wait for a release of GNU automake thataccepts these flags where they belong;@itemsurround the flags between quotes, but then you must set@var{program_DEPENDENCIES} too:@exampleprogram_LDADD = "-dlopen" libfoo.laprogram_DEPENDENCIES = libfoo.la@end example@itemset and @samp{AC_SUBST} variables @var{DLOPEN} and @var{DLPREOPEN} in@file{configure.in} and use @samp{@@DLOPEN@@} and @samp{@@DLPREOPEN@@}as replacements for the explicit flags @samp{-dlopen} and@samp{-dlpreopen} in @samp{program_LDADD}. Automake will discard@samp{AC_SUBST}ed variables from dependencies, so it will behave exactlyas we expect it to behave when it accepts these flags in@samp{program_LDADD}. But hey!, this is ugly!@end itemizeYou may use the @samp{program_LDFLAGS} variable to stuff in any flagsyou want to pass to libtool while linking @samp{program} (such as@samp{-static} to avoid linking uninstalled shared libtool libraries).Building a libtool library is almost as trivial@dots{} note the use of@samp{libhello_la_LDFLAGS} to pass the @samp{-version-info}(@pxref{Versioning}) option to libtool:@example# Build a libtool library, libhello.la for installation in libdir.lib_LTLIBRARIES = libhello.lalibhello_la_SOURCES = hello.c foo.clibhello_la_LDFLAGS = -version-info 3:12:1@end exampleThe @samp{-rpath} option is passed automatically by Automake (except forlibraries listed as @code{noinst_LTLIBRARIES}), so youshould not specify it.@xref{A Shared Library, Building a Shared Library, The Automake Manual,automake, The Automake Manual}, for more information.@node Configuring@section Configuring libtool@cindex configuring libtoolLibtool requires intimate knowledge of your compiler suite and operatingsystem in order to be able to create shared libraries and link againstthem properly. When you install the libtool distribution, asystem-specific libtool script is installed into your binary directory.However, when you distribute libtool with your own packages(@pxref{Distributing}), you do not always know which compiler suite andoperating system are used to compile your package.For this reason, libtool must be @dfn{configured} before it can beused. This idea should be familiar to anybody who has used a GNU@code{configure} script. @code{configure} runs a number of tests forsystem features, then generates the @file{Makefiles} (and possibly a@file{config.h} header file), after which you can run @code{make} andbuild the package.Libtool adds its own tests to your @code{configure} script in order togenerate a libtool script for the installer's host machine.@menu* AC_PROG_LIBTOOL:: Configuring @code{libtool} in @file{configure.in}.@end menu@node AC_PROG_LIBTOOL@subsection The @code{AC_PROG_LIBTOOL} macroIf you are using GNU Autoconf (or Automake), you should add a call to@code{AC_PROG_LIBTOOL} to your @file{configure.in} file. This macroadds many new tests to the @code{configure} script so that the generatedlibtool script will understand the characteristics of the host:@defmac AC_PROG_LIBTOOL@defmacx AM_PROG_LIBTOOLAdd support for the @samp{--enable-shared} and @samp{--disable-shared}@code{configure} flags.@footnote{@code{AC_PROG_LIBTOOL} requires thatyou define the @file{Makefile} variable @code{top_builddir} in your@file{Makefile.in}. Automake does this automatically, but Autoconfusers should set it to the relative path to the top of your builddirectory (@file{../..}, for example).} @code{AM_PROG_LIBTOOL} was theold name for this macro, and although supported at the moment isdeprecated.By default, this macro turns on shared libraries if they are available,and also enables static libraries if they don't conflict with the sharedlibraries. You can modify these defaults by calling either the@code{AC_DISABLE_SHARED} or @code{AC_DISABLE_STATIC} macros:@example# Turn off shared libraries during beta-testing, since they# make the build process take too long.AC_DISABLE_SHAREDAC_PROG_LIBTOOL@end exampleThe user may specify modified forms of the configure flags@samp{--enable-shared} and @samp{--enable-static} to choose whethershared or static libraries are built based on the name of the package.For example, to have shared @samp{bfd} and @samp{gdb} libraries built,but not shared @samp{libg++}, you can run all three @code{configure}scripts as follows:@exampletrick$ ./configure --enable-shared=bfd,gdb@end exampleIn general, specifying @samp{--enable-shared=@var{pkgs}} is the same asconfiguring with @samp{--enable-shared} every package named in thecomma-separated @var{pkgs} list, and every other package with@samp{--disable-shared}. The @samp{--enable-static=@var{pkgs}} flagbehaves similarly, but it uses @samp{--enable-static} and@samp{--disable-static}. The same applies to the@samp{--enable-fast-install=@var{pkgs}} flag, which uses@samp{--enable-fast-install} and @samp{--disable-fast-install}.The package name @samp{default} matches any packages which have not settheir name in the @code{PACKAGE} environment variable.This macro also sets the shell variable @var{LIBTOOL_DEPS}, that you canuse to automatically update the libtool script if it becomesout-of-date. In order to do that, add to your @file{configure.in}:@exampleAC_PROG_LIBTOOLAC_SUBST(LIBTOOL_DEPS)@end exampleand, to @file{Makefile.in} or @file{Makefile.am}:@exampleLIBTOOL_DEPS = @@LIBTOOL_DEPS@@libtool: $(LIBTOOL_DEPS) $(SHELL) ./config.status --recheck@end exampleIf you are using GNU automake, you can omit the assignment, as automakewill take care of it. You'll obviously have to create some dependencyon @file{libtool}.@end defmac@defmac AC_LIBTOOL_DLOPENEnable checking for dlopen support. This macro should be used ifthe package makes use of the @samp{-dlopen} and @samp{-dlpreopen} flags,otherwise libtool will assume that the system does not support dlopening.The macro must be called @strong{before} @code{AC_PROG_LIBTOOL}.@end defmac@defmac AC_LIBTOOL_WIN32_DLLThis macro should be used if the package has been ported to build cleandlls on win32 platforms. Usually this means that any library data itemsare exported with @code{__declspec(dllexport)} and imported with@code{__declspec(dllimport)}. If this macro is not used, libtool willassume that the package libraries are not dll clean and will build onlystatic libraries on win32 hosts.This macro must be called @strong{before} @code{AC_PROG_LIBTOOL}, andprovision must be made to pass @samp{-no-undefined} to @code{libtool}in link mode from the package @code{Makefile}. Naturally, if you pass@samp{-no-undefined}, you must ensure that all the library symbols@strong{really are} defined at link time!@end defmac@defmac AC_DISABLE_FAST_INSTALLChange the default behaviour for @code{AC_PROG_LIBTOOL} to disableoptimization for fast installation. The user may still override thisdefault, depending on platform support, by specifying@samp{--enable-fast-install}.@end defmac@defmac AC_DISABLE_SHARED@defmacx AM_DISABLE_SHAREDChange the default behaviour for @code{AC_PROG_LIBTOOL} to disableshared libraries. The user may still override this default byspecifying @samp{--enable-shared}.@end defmac@defmac AC_DISABLE_STATIC@defmacx AM_DISABLE_STATICChange the default behaviour for @code{AC_PROG_LIBTOOL} to disablestatic libraries. The user may still override this default byspecifying @samp{--enable-static}.@end defmacThe tests in @code{AC_PROG_LIBTOOL} also recognize the followingenvironment variables:@defvar CCThe C compiler that will be used by the generated @code{libtool}. Ifthis is not set, @code{AC_PROG_LIBTOOL} will look for @code{gcc} or@code{cc}.@end defvar@defvar CFLAGSCompiler flags used to generate standard object files. If this is notset, @code{AC_PROG_LIBTOOL} will not use any such flags. It affectsonly the way @code{AC_PROG_LIBTOOL} runs tests, not the produced@code{libtool}.@end defvar@defvar CPPFLAGSC preprocessor flags. If this is not set, @code{AC_PROG_LIBTOOL} willnot use any such flags. It affects only the way @code{AC_PROG_LIBTOOL}runs tests, not the produced @code{libtool}.@end defvar@defvar LDThe system linker to use (if the generated @code{libtool} requires one).If this is not set, @code{AC_PROG_LIBTOOL} will try to find out what isthe linker used by @var{CC}.@end defvar@defvar LDFLAGSThe flags to be used by @code{libtool} when it links a program. Ifthis is not set, @code{AC_PROG_LIBTOOL} will not use any such flags. Itaffects only the way @code{AC_PROG_LIBTOOL} runs tests, not the produced@code{libtool}.@end defvar@defvar LIBSThe libraries to be used by @code{AC_PROG_LIBTOOL} when it links aprogram. If this is not set, @code{AC_PROG_LIBTOOL} will not use anysuch flags. It affects only the way @code{AC_PROG_LIBTOOL} runs tests,not the produced @code{libtool}.@end defvar@defvar NMProgram to use rather than checking for @code{nm}.@end defvar@defvar RANLIBProgram to use rather than checking for @code{ranlib}.@end defvar@defvar LN_SA command that creates a link of a program, a soft-link if possible, ahard-link otherwise. @code{AC_PROG_LIBTOOL} will check for a suitableprogram if this variable is not set.@end defvar@defvar DLLTOOLProgram to use rather than checking for @code{dlltool}. Only meaningfulfor Cygwin/MS-Windows.@end defvar@defvar OBJDUMPProgram to use rather than checking for @code{objdump}. Only meaningfulfor Cygwin/MS-Windows.@end defvar@defvar ASProgram to use rather than checking for @code{as}. Only used onCygwin/MS-Windows at the moment.@end defvar@pindex aclocalWhen you invoke the @code{libtoolize} program (@pxref{Invokinglibtoolize}), it will tell you where to find a definition of@code{AC_PROG_LIBTOOL}. If you use Automake, the @code{aclocal} programwill automatically add @code{AC_PROG_LIBTOOL} support to your@code{configure} script.Nevertheless, it is advisable to include a copy of @file{libtool.m4} in@file{acinclude.m4}, so that, even if @file{aclocal.m4} and@file{configure} are rebuilt for any reason, the appropriate libtoolmacros will be used. The alternative is to hope the user will have acompatible version of @file{libtool.m4} installed and accessible for@code{aclocal}. This may lead to weird errors when versions don'tmatch.@node Distributing@section Including libtool in your packageIn order to use libtool, you need to include the following files withyour package:@table @file@item config.guess@pindex config.guessAttempt to guess a canonical system name.@item config.sub@pindex config.subCanonical system name validation subroutine script.@item ltmain.sh@pindex ltmain.shA generic script implementing basic libtool functionality.@end tableNote that the libtool script itself should @emph{not} be included withyour package. @xref{Configuring}.You should use the @code{libt
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -