manpagez: man pages & more
info autoconf
Home | html | info | man

File: autoconf.info,  Node: Generic Headers,  Prev: Particular Headers,  Up: Header Files

5.6.3 Generic Header Checks
---------------------------

These macros are used to find system header files not covered by the
"particular" test macros.  If you need to check the contents of a header
as well as find out whether it is present, you have to write your own
test for it (*note Writing Tests::).

 -- Macro: AC_CHECK_HEADER (HEADER-FILE, [ACTION-IF-FOUND],
          [ACTION-IF-NOT-FOUND], [INCLUDES])
     If the system header file HEADER-FILE is compilable, execute shell
     commands ACTION-IF-FOUND, otherwise execute ACTION-IF-NOT-FOUND.
     If you just want to define a symbol if the header file is
     available, consider using ‘AC_CHECK_HEADERS’ instead.

     INCLUDES should be the appropriate “prerequisite” code, i.e.
     whatever might be required to appear above ‘#include ’
     for it to compile without error.  This can be anything, but will
     normally be additional ‘#include’ directives.  If INCLUDES is
     omitted or empty, ‘configure’ will use the contents of the macro
     ‘AC_INCLUDES_DEFAULT’.  *Note Default Includes::.

     This macro used to check only for the _presence_ of a header, not
     whether its contents were acceptable to the compiler.  Some older
     ‘configure’ scripts rely on this behavior, so it is still available
     by specifying ‘-’ as INCLUDES.  This mechanism is deprecated as of
     Autoconf 2.70; situations where a preprocessor-only check is
     required should use ‘AC_PREPROC_IFELSE’.  *Note Running the
     Preprocessor::.

     This macro caches its result in the ‘ac_cv_header_HEADER-FILE’
     variable, with characters not suitable for a variable name mapped
     to underscores.

 -- Macro: AC_CHECK_HEADERS (HEADER-FILE..., [ACTION-IF-FOUND],
          [ACTION-IF-NOT-FOUND], [INCLUDES])
     For each given system header file HEADER-FILE in the
     blank-separated argument list that exists, define
     ‘HAVE_HEADER-FILE’ (in all capitals).  If ACTION-IF-FOUND is given,
     it is additional shell code to execute when one of the header files
     is found.  You can give it a value of ‘break’ to break out of the
     loop on the first match.  If ACTION-IF-NOT-FOUND is given, it is
     executed when one of the header files is not found.

     INCLUDES is interpreted as in ‘AC_CHECK_HEADER’, in order to choose
     the set of preprocessor directives supplied before the header under
     test.

     This macro caches its result in the ‘ac_cv_header_HEADER-FILE’
     variable, with characters not suitable for a variable name mapped
     to underscores.

 -- Macro: AC_CHECK_HEADERS_ONCE (HEADER-FILE...)
     For each given system header file HEADER-FILE in the
     blank-separated argument list that exists, define
     ‘HAVE_HEADER-FILE’ (in all capitals).

     If you do not need the full power of ‘AC_CHECK_HEADERS’, this
     variant generates smaller, faster ‘configure’ files.  All headers
     passed to ‘AC_CHECK_HEADERS_ONCE’ are checked for in one pass,
     early during the ‘configure’ run.  The checks cannot be
     conditionalized, you cannot specify an ACTION-IF-FOUND or
     ACTION-IF-NOT-FOUND, and ‘AC_INCLUDES_DEFAULT’ is always used for
     the prerequisites.

   In previous versions of Autoconf, these macros merely checked whether
the header was accepted by the preprocessor.  This was changed because
the old test was inappropriate for typical uses.  Headers are typically
used to compile, not merely to preprocess, and the old behavior
sometimes accepted headers that clashed at compile-time (*note Present
But Cannot Be Compiled::).  If for some reason it is inappropriate to
check whether a header is compilable, you should use ‘AC_PREPROC_IFELSE’
(*note Running the Preprocessor::) instead of these macros.

   Requiring each header to compile improves the robustness of the test,
but it also requires you to make sure that the INCLUDES are correct.
Most system headers nowadays make sure to ‘#include’ whatever they
require, or else have their dependencies satisfied by
‘AC_INCLUDES_DEFAULT’ (*note Default Includes::), but *note Header
Portability::, for known exceptions.  In general, if you are looking for
‘bar.h’, which requires that ‘foo.h’ be included first if it exists, you
should do something like this:

     AC_CHECK_HEADERS([foo.h])
     AC_CHECK_HEADERS([bar.h], [], [],
     [#ifdef HAVE_FOO_H
     # include 
     #endif
     ])

© manpagez.com 2000-2025
Individual documents may contain additional copyright information.