Previous: , Up: Header Files   [Contents][Index]


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 (see 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 <header-file>’ 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. See 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. See 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 (see Header 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 (see 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 (see Default Includes), but see Portability of Headers, 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 <foo.h>
#endif
])

Previous: Particular Header Checks, Up: Header Files   [Contents][Index]