The following macros check for the declaration of variables and functions. If there is no macro specifically defined to check for a symbol you need, then you can use the general macros (the section called “Generic Declaration Checks”) or, for more complex tests, you may use AC_TRY_COMPILE (the section called “Examining Syntax”).
The following macros check for certain declarations.
function>AC_DECL_SYS_SIGLIST/function> Define SYS_SIGLIST_DECLARED if the variable sys_siglist is declared in a system header file, either signal.h or unistd.h.
These macros are used to find declarations not covered by the "particular" test macros.
function>AC_CHECK_DECL/function> (symbol, [action-if-found], [action-if-not-found], [includes = default-includes]) If symbol (a function or a variable) is not declared in includes and a declaration is needed, run the shell commands action-if-not-found, otherwise action-if-found. If no includes are specified, the default includes are used (the section called “Default Includes ”).
This macro actually tests whether it is valid to use symbol as an r-value, not if it is really declared, because it is much safer to avoid introducing extra declarations when they are not needed.
function>AC_CHECK_DECLS/function> (symbols, [action-if-found], [action-if-not-found], [includes = default-includes]) For each of the symbols (comma-separated list), define HAVE_DECL_symbol (in all capitals) to 1 if symbol is declared, otherwise to 0. If action-if-not-found is given, it is additional shell code to execute when one of the function declarations is needed, otherwise action-if-found is executed.
This macro uses an m4 list as first argument:
AC_CHECK_DECLS(strdup) AC_CHECK_DECLS([strlen]) AC_CHECK_DECLS([malloc, realloc, calloc, free])
Unlike the other AC_CHECK_*S macros, when a symbol is not declared, HAVE_DECL_symbol is defined to 0 instead of leaving HAVE_DECL_symbol undeclared. When you are sure that the check was performed, use HAVE_DECL_symbol just like any other result of Autoconf:
#if !HAVE_DECL_SYMBOL extern char *symbol; #endif
If the test may have not been performed, however, because it is safer not to declare a symbol than to use a declaration that conflicts with the system's one, you should use:
#if defined HAVE_DECL_MALLOC !HAVE_DECL_MALLOC char *malloc (size_t *s); #endif
You fall into the second category only in extreme situations: either your files may be used without being configured, or they are used during the configuration. In most cases the traditional approach is enough.