1 @node Searching for Libraries
2 @section Searching for Libraries
4 The following macros check for the presence or location of certain C, C++, or
5 Fortran library archive files.
7 @unnumberedsubsec Simple Library Tests
9 The macros @code{AC_CHECK_LIB}, @code{AC_SEARCH_LIBS} from GNU Autoconf check
10 for the presence of certain C, C++, or Fortran library archive files.
11 The libraries are looked up in the default linker path---a system dependent
12 list of directories, that usually contains the @file{/usr/lib} directory---and
13 those directories given by @code{-L} options in the @code{LDFLAGS}
16 @unnumberedsubsec Locating Libraries
18 The following macros, defined in the Gnulib module @code{havelib}, search for
19 the location of certain C, C++, or Fortran library archive files and make the
20 found location available to the compilation process and to further Autoconf
23 @deffn Macro @code{AC_LIB_LINKFLAGS(@var{name}, [@var{dependencies}])}
25 Searches for @code{lib<@var{name}>} and the libraries corresponding to
26 explicit and implicit dependencies. Sets and AC_SUBSTs the
27 @code{LIB<@var{NAME}>} and @code{LTLIB<@var{NAME}>} variables (with
28 @code{<@var{NAME}>} in upper case) and augments the @code{CPPFLAGS} variable
31 This macro should be used when @code{lib<@var{name}>} is expected to be found.
34 @deffn Macro @code{AC_LIB_HAVE_LINKFLAGS(@var{name}, [@var{dependencies}], [@var{includes}], [@var{testcode}], [@var{missing-message}])}
36 Searches for @code{lib<@var{name}>} and the libraries corresponding to
37 explicit and implicit dependencies, together with the specified include files
38 and the ability to compile and link the specified @var{testcode}. The
39 @var{missing-message} defaults to @code{no} and may contain additional hints
40 for the user. If found, it sets and AC_SUBSTs @code{HAVE_LIB<@var{NAME}>=yes}
41 and the @code{LIB<@var{NAME}>} and @code{LTLIB<@var{NAME}>} variables (with
42 @code{<@var{NAME}>} in upper case) and augments the @code{CPPFLAGS} variable
43 by @code{-I} options, and #defines @code{HAVE_LIB<@var{NAME}>} to 1.
44 Otherwise, it sets and AC_SUBSTs @code{HAVE_LIB<@var{NAME}>=no} and
45 @code{LIB<@var{NAME}>} and @code{LTLIB<@var{NAME}>} to empty.
48 These macros assume that when a library is installed in
49 @code{@var{some_directory}/lib}, its include files are installed in
50 @code{@var{some_directory}/include}.
52 The complexities that @code{AC_LIB_LINKFLAGS} and @code{AC_LIB_HAVE_LINKFLAGS}
53 deal with are the following:
57 The library is not necessarily already in the search path (@code{CPPFLAGS} for
58 the include file search path, @code{LDFLAGS} for the library search path).
59 The macro provides a @samp{--with-lib<@var{name}>} option. The user of the
60 @samp{configure} script can use this option to indicate the location of the
61 library and its include files. If not provided, the @code{--prefix} directory
65 The library is not necessarily already in the run time library search path.
66 To avoid the need for setting an environment variable like
67 @code{LD_LIBRARY_PATH}, the macro adds the appropriate run time search path
68 options to the @code{LIB<@var{NAME}>} variable. This works on most systems.
69 It can also be inhibited: The user of @samp{configure} can use the
70 @code{--disable-rpath} option to force an installation that doesn't contain
71 hardcoded library search paths but instead may require the use of an
72 environment variable like @code{LD_LIBRARY_PATH}.
75 The macros also set a variable @code{LTLIB<@var{NAME}>}, that should be used
76 when linking with libtool. Both @code{LTLIB<@var{NAME}>} and
77 @code{LIB<@var{NAME}>} contain essentially the same option, but where
78 @code{LIB<@var{NAME}>} contains platform dependent flags like
79 @samp{-Wl,-rpath}, @code{LTLIB<@var{NAME}>} contains platform independent
82 @unnumberedsubsubsec Example of using @code{AC_LIB_LINKFLAGS}
84 Suppose you want to use @code{libz}, the compression library.
88 In configure.ac you add the line
91 AC_CONFIG_AUX_DIR([build-aux])
96 Note that since the @code{AC_LIB_LINKFLAGS} invocation modifies the CPPFLAGS,
97 it should precede all tests that check for header files, declarations,
101 To the package's @file{build-aux} directory you add the file
102 @file{config.rpath}, also part of the Gnulib @code{havelib} module.
103 (@code{gnulib-tool} will usually do this for you automatically.)
106 In @code{Makefile.in} you add @code{@@LIBZ@@} to the link command line of
107 your program. Or, if you are using Automake, you add @code{$(LIBZ)} to the
108 @code{LDADD} variable that corresponds to your program.
111 @unnumberedsubsubsec Dependencies
113 The dependencies list is a space separated list of library names that
114 @code{lib@var{name}} is known to depend upon. Example: If @code{libfooy}
115 depends on @code{libfoox}, and @code{libfooz} depends on @code{libfoox} and
116 @code{libfooy}, you can write:
119 AC_LIB_LINKFLAGS([foox])
120 AC_LIB_LINKFLAGS([fooy], [foox])
121 AC_LIB_LINKFLAGS([fooz], [foox fooy])
125 Explicit dependencies are necessary if you cannot assume that a @code{.la}
126 file, created by libtool, is installed. If you can assume that
127 @code{libfooy.la} is installed by libtool (and has not been omitted by the
128 package distributor!), you can omit the explicit dependency and just write
131 AC_LIB_LINKFLAGS([fooy])
135 This way, you don't need to know in advance which libraries the needed
136 library depends upon.
138 @unnumberedsubsubsec Static vs. shared
140 The macros find the libraries regardless whether they are installed as
141 shared or static libraries.
143 @unnumberedsubsubsec @code{CPPFLAGS} vs. @code{LDFLAGS}
145 The macros determine the directories that should be added to the compiler
146 preprocessor's search path and to the linker's search path. For the
147 compiler preprocessor, @code{-I} options with the necessary directories are
148 added to the @code{CPPFLAGS} variable, for use by the whole package. For
149 the linker, appropriate options are added to the @code{LIB<@var{NAME}>} and
150 @code{LTLIB<@var{NAME}>} variables, for use during linking by those programs
151 and libraries that need the dependency on @code{lib<@var{name}>}. You need
152 to use the value of @code{LIB<@var{NAME}>} or @code{LTLIB<@var{NAME}>} in the
153 Makefiles. @code{LTLIB<@var{NAME}>} is for use with libtool, whereas
154 @code{LIB<@var{NAME}>} is for when libtool is not involved in linking.
156 The macros do not check whether the include files and the library found
157 match. If you want to verify this at configure time, one technique is
158 to have a version number in the include files and a version number in the
161 #define LIB@var{NAME}_VERSION 10203
162 extern int lib@var{name}_version; /* initialized to LIB@var{NAME}_VERSION */
167 AC_TRY_RUN([int main () @{ return lib@var{name}_version != LIB@var{NAME}_VERSION; @}])
170 @unnumberedsubsubsec Bi-arch systems
172 A bi-arch system is one where
175 the processor has a 32-bit execution mode and a 64-bit execution mode
176 (for example, x86_64, ia64, sparc64, powerpc64), and
178 32-bit mode libraries and executables and 64-bit mode libraries are both
181 32-bit mode libraries and object files cannot be mixed with 64-bit mode
185 On several types of such systems, for historical reasons, the 32-bit libraries
186 are installed in @file{@var{prefix}/lib}, whereas the 64-bit libraries are
190 @file{@var{prefix}/lib64} on many glibc systems,
192 @file{@var{prefix}/lib/64} on Solaris systems.
195 On such systems, in 64-bit mode, @command{configure} will search for the
196 libraries in @file{@var{prefix}/lib64} or @file{@var{prefix}/lib/64},
197 respectively, not in @file{@var{prefix}/lib}. A user can adhere to these
198 system-wide conventions by using the @samp{--libdir} option when installing
199 packages. When a user has already installed packages in 64-bit mode using
200 the GNU default @samp{--libdir=@var{prefix}/lib}, he can make this directory
201 adhere to the system-wide convention by placing a symbolic link:
203 @item On glibc systems:
204 @code{ln -s lib @var{prefix}/lib64}
205 @item On Solaris systems:
206 @code{ln -s . @var{prefix}/lib/64}