Next: Controlling the Exported Symbols of Shared Libraries, Up: Build Infrastructure Modules [Contents][Index]
The following macros check for the presence or location of certain C, C++, or Fortran library archive files.
The macros AC_CHECK_LIB
, AC_SEARCH_LIBS
from GNU Autoconf check
for the presence of certain C, C++, or Fortran library archive files.
The libraries are looked up in the default linker path—a system dependent
list of directories, that usually contains the /usr/lib directory—and
those directories given by -L
options in the LDFLAGS
variable.
The following macros, defined in the Gnulib module havelib
, search for
the location of certain C, C++, or Fortran library archive files and make the
found location available to the compilation process and to further Autoconf
tests.
AC_LIB_LINKFLAGS(name, [dependencies])
¶Searches for lib<name>
and the libraries corresponding to
explicit and implicit dependencies. Sets and AC_SUBSTs the
LIB<NAME>
and LTLIB<NAME>
variables (with
<NAME>
in upper case) and augments the CPPFLAGS
variable
by -I
options.
This macro should be used when lib<name>
is expected to be found.
AC_LIB_HAVE_LINKFLAGS(name, [dependencies], [includes], [testcode], [missing-message])
¶Searches for lib<name>
and the libraries corresponding to
explicit and implicit dependencies, together with the specified include files
and the ability to compile and link the specified testcode. The
missing-message defaults to no
and may contain additional hints
for the user. If found, it sets and AC_SUBSTs HAVE_LIB<NAME>=yes
and the LIB<NAME>
and LTLIB<NAME>
variables (with
<NAME>
in upper case) and augments the CPPFLAGS
variable
by -I
options, and #defines HAVE_LIB<NAME>
to 1.
Otherwise, it sets and AC_SUBSTs HAVE_LIB<NAME>=no
and
LIB<NAME>
and LTLIB<NAME>
to empty.
These macros assume that when a library is installed in
some_directory/lib
, its include files are installed in
some_directory/include
.
The complexities that AC_LIB_LINKFLAGS
and AC_LIB_HAVE_LINKFLAGS
deal with are the following:
CPPFLAGS
for
the include file search path, LDFLAGS
for the library search path).
The macro provides a ‘--with-lib<name>’ option. The user of the
‘configure’ script can use this option to indicate the location of the
library and its include files. If not provided, the --prefix
directory
is searched as well.
LD_LIBRARY_PATH
, the macro adds the appropriate run time search path
options to the LIB<NAME>
variable. This works on most systems.
It can also be inhibited: The user of ‘configure’ can use the
--disable-rpath
option to force an installation that doesn’t contain
hardcoded library search paths but instead may require the use of an
environment variable like LD_LIBRARY_PATH
.
The macros also set a variable LTLIB<NAME>
, that should be used
when linking with libtool. Both LTLIB<NAME>
and
LIB<NAME>
contain essentially the same option, but where
LIB<NAME>
contains platform dependent flags like
‘-Wl,-rpath’, LTLIB<NAME>
contains platform independent
flags like ‘-R’.
If you, by mistake, use LIB<NAME>
instead of
LTLIB<NAME>
when linking with libtool, you will observe that the
binaries created in the build dir will prefer the shared libraries in the
installation directories over the shared libraries in the build dir; this can
lead to all sorts of build failures, test failures, or crashes!
If you, on the other hand, by mistake, use LTLIB<NAME>
instead of
LIB<NAME>
when linking without libtool, you will observe
build failures, because the ‘-R’ options contained in
LTLIB<NAME>
are not valid options to compilers such as GCC.
AC_LIB_LINKFLAGS
CPPFLAGS
vs. LDFLAGS
AC_LIB_LINKFLAGS
Suppose you want to use libz
, the compression library.
AC_CONFIG_AUX_DIR([build-aux]) AC_LIB_LINKFLAGS([z])
Note that since the AC_LIB_LINKFLAGS
invocation modifies the CPPFLAGS,
it should precede all tests that check for header files, declarations,
structures or types.
havelib
module.
(gnulib-tool
will usually do this for you automatically.)
Makefile.in
you add @LIBZ@
to the link command line of
your program. Or, if you are using Automake, you add $(LIBZ)
to the
LDADD
variable that corresponds to your program.
The dependencies list is a space separated list of library names that
libname
is known to depend upon. Example: If libfooy
depends on libfoox
, and libfooz
depends on libfoox
and
libfooy
, you can write:
AC_LIB_LINKFLAGS([foox]) AC_LIB_LINKFLAGS([fooy], [foox]) AC_LIB_LINKFLAGS([fooz], [foox fooy])
Explicit dependencies are necessary if you cannot assume that a .la
file, created by libtool, is installed. If you can assume that
libfooy.la
is installed by libtool (and has not been omitted by the
package distributor!), you can omit the explicit dependency and just write
AC_LIB_LINKFLAGS([fooy])
This way, you don’t need to know in advance which libraries the needed library depends upon.
CPPFLAGS
vs. LDFLAGS
The macros determine the directories that should be added to the compiler
preprocessor’s search path and to the linker’s search path. For the
compiler preprocessor, -I
options with the necessary directories are
added to the CPPFLAGS
variable, for use by the whole package. For
the linker, appropriate options are added to the LIB<NAME>
and
LTLIB<NAME>
variables, for use during linking by those programs
and libraries that need the dependency on lib<name>
. You need
to use the value of LIB<NAME>
or LTLIB<NAME>
in the
Makefiles. LTLIB<NAME>
is for use with libtool, whereas
LIB<NAME>
is for when libtool is not involved in linking.
The macros do not check whether the include files and the library found match. If you want to verify this at configure time, one technique is to have a version number in the include files and a version number in the library, like this:
#define LIBNAME_VERSION 10203 extern int libname_version; /* initialized to LIBNAME_VERSION */
and use a test like
AC_TRY_RUN([int main () { return libname_version != LIBNAME_VERSION; }])
A bi-arch system is one where
On several types of such systems, for historical reasons, the 32-bit libraries are installed in prefix/lib, whereas the 64-bit libraries are installed in
On such systems, in 64-bit mode, configure
will search for the
libraries in prefix/lib64 or prefix/lib/64,
respectively, not in prefix/lib. A user can adhere to these
system-wide conventions by using the ‘--libdir’ option when installing
packages. When a user has already installed packages in 64-bit mode using
the GNU default ‘--libdir=prefix/lib’, he can make this directory
adhere to the system-wide convention by placing a symbolic link:
ln -s lib prefix/lib64
ln -s . prefix/lib/64