| [ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
11.6 How to distribute libltdl with your package
Even though libltdl is installed together with libtool, you may wish to include libltdl in the distribution of your package, for the convenience of users of your package that don’t have libtool or libltdl installed, or if you are using features of a very new version of libltdl that you don’t expect your users to have yet. In such cases, you must decide which flavor of libltdl you want to use: a convenience library or an installable libtool library.
The most simplistic way to add libltdl to your package is to
copy all the ‘libltdl’ source files to a subdirectory within
your package and to build and link them along with the rest of your
sources. To help you do this, the m4 macros for Autoconf are
available in ‘ltdl.m4’. You must ensure that they are available
in ‘aclocal.m4’ before you run Autoconf(12). Having made the macros available, you must add a call to the
‘LTDL_INIT’ macro (after the call to ‘LT_INIT’)
to your package’s ‘configure.ac’ to
perform the configure time checks required to build the library
correctly. Unfortunately, this method has problems if you then try to
link the package binaries with an installed libltdl, or a library that
depends on libltdl, because of the duplicate symbol definitions. For
example, ultimately linking against two different versions of libltdl,
or against both a local convenience library and an installed libltdl
is bad. Ensuring that only one copy of the libltdl sources are linked
into any program is left as an exercise for the reader.
- Macro: LT_CONFIG_LTDL_DIR (directory)
Declare directory to be the location of the
libltdlsource files, forlibtoolize --ltdlto place them. See section Invokinglibtoolize, for more details. Provided that you add an appropriateLT_CONFIG_LTDL_DIRcall in your ‘configure.ac’ before callinglibtoolize, the appropriatelibltdlfiles will be installed automatically.
- Macro: LTDL_INIT (options)
- Macro: LT_WITH_LTDL
- Macro: AC_WITH_LTDL
AC_WITH_LTDLandLT_WITH_LTDLare deprecated names for older versions of this macro;autoupdatewill update your ‘configure.ac’ file.This macro adds the following options to the
configurescript:- ‘--with-ltdl-include installed-ltdl-header-dir’
The
LTDL_INITmacro will look in the standard header file locations to find the installedlibltdlheaders. IfLTDL_INITcan’t find them by itself, the person who builds your package can use this option to tellconfigurewhere the installedlibltdlheaders are.- ‘--with-ltdl-lib installed-ltdl-library-dir’
Similarly, the person building your package can use this option to help
configurefind the installed ‘libltdl.la’.- ‘--with-included-ltdl’
If there is no installed
libltdl, or in any case if the person building your package would rather use thelibltdlsources shipped with the package in the subdirectory named byLT_CONFIG_LTDL_DIR, they should pass this option toconfigure.
If the ‘--with-included-ltdl’ is not passed at configure time, and an installed
libltdlis not found(13), thenconfigurewill exit immediately with an error that asks the user to either specify the location of an installedlibltdlusing the ‘--with-ltdl-include’ and ‘--with-ltdl-lib’ options, or to build with thelibltdlsources shipped with the package by passing ‘--with-included-ltdl’.If an installed
libltdlis found, thenLIBLTDLis set to the link flags needed to use it, andLTDLINCLto the preprocessor flags needed to find the installed headers, andLTDLDEPSwill be empty. Note, however, that no version checking is performed. You should manually check for thelibltdlfeatures you need in ‘configure.ac’:LT_INIT([dlopen]) LTDL_INIT # The lt_dladvise_init symbol was added with libtool-2.2 if test "x$with_included_ltdl" != "xyes"; then save_CFLAGS="$CFLAGS" save_LDFLAGS="$LDFLAGS" CFLAGS="$CFLAGS $LTDLINCL" LDFLAGS="$LDFLAGS $LIBLTDL" AC_CHECK_LIB([ltdl], [lt_dladvise_init], [], [AC_MSG_ERROR([installed libltdl is too old])]) LDFLAGS="$save_LDFLAGS" CFLAGS="$save_CFLAGS" fioptions may include no more than one of the following build modes depending on how you want your project to build
libltdl: ‘nonrecursive’, ‘recursive’, or ‘subproject’. In order forlibtoolizeto detect this option correctly, if you supply one of these arguments, they must be given literally (i.e., macros or shell variables that expand to the correct ltdl mode will not work).- ‘nonrecursive’
This is how the Libtool project distribution builds the
libltdlwe ship and install. If you wish to use Automake to buildlibltdlwithout invoking a recursive make to descend into thelibltdlsubdirectory, then use this option. You will need to set your configuration up carefully to make this work properly, and you will need releases of Autoconf and Automake that supportsubdir-objectsandLIBOBJDIRproperly. In your ‘configure.ac’, add:AM_INIT_AUTOMAKE([subdir-objects]) AC_CONFIG_HEADERS([config.h]) LT_CONFIG_LTDL_DIR([libltdl]) LT_INIT([dlopen]) LTDL_INIT([nonrecursive])
You have to use a config header, but it may have a name different than ‘config.h’.
Also, add the following near the top of your ‘Makefile.am’:
AM_CPPFLAGS = AM_LDFLAGS = BUILT_SOURCES = EXTRA_DIST = CLEANFILES = MOSTLYCLEANFILES = include_HEADERS = noinst_LTLIBRARIES = lib_LTLIBRARIES = EXTRA_LTLIBRARIES = include libltdl/Makefile.inc
Unless you build no other libraries from this ‘Makefile.am’, you will also need to change
lib_LTLIBRARIESto assign with ‘+=’ so that thelibltdltargets declared in ‘Makefile.inc’ are not overwritten.- ‘recursive’
This build mode still requires that you use Automake, but (in contrast with ‘nonrecursive’) uses the more usual device of starting another
makeprocess in the ‘libltdl’ subdirectory. To use this mode, you should add to your ‘configure.ac’:AM_INIT_AUTOMAKE AC_CONFIG_HEADERS([config.h]) LT_CONFIG_LTDL_DIR([libltdl]) LT_INIT([dlopen]) LTDL_INIT([recursive]) AC_CONFIG_FILES([libltdl/Makefile])
Again, you have to use a config header, but it may have a name different than ‘config.h’ if you like.
Also, add this to your ‘Makefile.am’:
SUBDIRS = libltdl
- ‘subproject’
This mode is the default unless you explicitly add
recursiveornonrecursiveto yourLTDL_INIToptions;subprojectis the only mode supported by previous releases of libltdl. Even if you do not use Autoconf in the parent project, then, in ‘subproject’ mode, stilllibltdlcontains all the necessary files to configure and build itself – you just need to arrange for your build system to call ‘libltdl/configure’ with appropriate options, and then runmakein thelibltdlsubdirectory.If you are using Autoconf and Automake, then you will need to add the following to your ‘configure.ac’:
LT_CONFIG_LTDL_DIR([libltdl]) LTDL_INIT
and to ‘Makefile.am’:
SUBDIRS = libltdl
Aside from setting the libltdl build mode, there are other keywords that you can pass to
LTDL_INITto modify its behavior when ‘--with-included-ltdl’ has been given:- ‘convenience’
This is the default unless you explicitly add
installableto yourLTDL_INIToptions.This keyword will cause options to be passed to the
configurescript in the subdirectory named byLT_CONFIG_LTDL_DIRin order to cause it to be built as a convenience library. If you’re not using automake, you will need to definetop_build_prefix,top_builddir, andtop_srcdirin your makefile so thatLIBLTDL,LTDLDEPS, andLTDLINCLexpand correctly.One advantage of the convenience library is that it is not installed, so the fact that you use
libltdlwill not be apparent to the user, and it won’t overwrite a pre-installed version oflibltdlthe system might already have in the installation directory. On the other hand, if you want to upgradelibltdlfor any reason (e.g. a bugfix) you’ll have to recompile your package instead of just replacing the shared installed version oflibltdl. However, if your programs or libraries are linked with other libraries that use such a pre-installed version oflibltdl, you may get linker errors or run-time crashes. Another problem is that you cannot link the convenience library into more than one libtool library, then link a single program with those libraries, because you may get duplicate symbols. In general you can safely use the convenience library in programs that don’t depend on other libraries that might uselibltdltoo.- ‘installable’
This keyword will pass options to the
configurescript in the subdirectory named byLT_CONFIG_LTDL_DIRin order to cause it to be built as an installable library. If you’re not using automake, you will need to definetop_build_prefix,top_builddirandtop_srcdirin your makefile so thatLIBLTDL,LTDLDEPS, andLTDLINCLare expanded properly.Be aware that you could overwrite another
libltdlalready installed to the same directory if you use this option.
Whatever method you use, ‘LTDL_INIT’ will define the shell variable
LIBLTDL to the link flag that you should use to link with
libltdl, the shell variable LTDLDEPS to the files that
can be used as a dependency in ‘Makefile’ rules, and the shell
variable LTDLINCL to the preprocessor flag that you should use to
compile programs that include ‘ltdl.h’. So, when you want to link a
program with libltdl, be it a convenience, installed or installable
library, just use ‘$(LTDLINCL)’ for preprocessing and compilation,
and ‘$(LIBLTDL)’ for linking.
-
If your package is built using an installed version of
libltdl,LIBLTDLwill be set to the compiler flags needed to link against the installed library,LTDLDEPSwill be empty, andLTDLINCLwill be set to the compiler flags needed to find thelibltdlheader files. -
If your package is built using the convenience libltdl,
LIBLTDLandLTDLDEPSwill be the pathname for the convenience version of libltdl (starting with ‘${top_builddir}/’ or ‘${top_build_prefix}’) andLTDLINCLwill be ‘-I’ followed by the directory that contains ‘ltdl.h’ (starting with ‘${top_srcdir}/’). -
If an installable version of the included
libltdlis being built, its pathname starting with ‘${top_builddir}/’ or ‘${top_build_prefix}’, will be stored inLIBLTDLandLTDLDEPS, andLTDLINCLwill be set just like in the case of convenience library.
You should probably also use the ‘dlopen’ option to LT_INIT
in your ‘configure.ac’, otherwise libtool will assume no dlopening
mechanism is supported, and revert to dlpreopening, which is probably not
what you want. Avoid using the ‘-static’,
‘-static-libtool-libs’, or ‘-all-static’
switches when linking programs with libltdl. This will not work on
all platforms, because the dlopening functions may not be available
for static linking.
The following example shows you how to embed an installable libltdl in
your package. In order to use the convenience variant, just replace the
LTDL_INIT option ‘installable’ with ‘convenience’. We
assume that libltdl was embedded using ‘libtoolize --ltdl’.
configure.ac:
... # Name the subdirectory that contains libltdl sources LT_CONFIG_LTDL_DIR([libltdl]) # Configure libtool with dlopen support if possible LT_INIT([dlopen]) # Enable building of the installable libltdl library LTDL_INIT([installable]) ...
Makefile.am:
... SUBDIRS = libltdl AM_CPPFLAGS = $(LTDLINCL) myprog_LDFLAGS = -export-dynamic myprog_LDADD = $(LIBLTDL) -dlopen self -dlopen foo1.la myprog_DEPENDENCIES = $(LTDLDEPS) foo1.la ...
- Macro: LTDL_INSTALLABLE
- Macro: AC_LIBLTDL_INSTALLABLE
These macros are deprecated, the ‘installable’ option to
LTDL_INITshould be used instead.
- Macro: LTDL_CONVENIENCE
- Macro: AC_LIBLTDL_CONVENIENCE
These macros are deprecated, the ‘convenience’ option to
LTDL_INITshould be used instead.
| [ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on December 1, 2011 using texi2html 5.0.
