File: autoconf.info, Node: Running the Linker, Next: Runtime, Prev: Running the Compiler, Up: Writing Tests 6.5 Running the Linker ====================== To check for a library, a function, or a global variable, Autoconf ‘configure’ scripts try to compile and link a small program that uses it. This is unlike Metaconfig, which by default uses ‘nm’ or ‘ar’ on the C library to try to figure out which functions are available. Trying to link with the function is usually a more reliable approach because it avoids dealing with the variations in the options and output formats of ‘nm’ and ‘ar’ and in the location of the standard libraries. It also allows configuring for cross-compilation or checking a function's runtime behavior if needed. On the other hand, it can be slower than scanning the libraries once, but accuracy is more important than speed. ‘AC_LINK_IFELSE’ is used to compile test programs to test for functions and global variables. It is also used by ‘AC_CHECK_LIB’ to check for libraries (*note Libraries::), by adding the library being checked for to ‘LIBS’ temporarily and trying to link a small program. -- Macro: AC_LINK_IFELSE (INPUT, [ACTION-IF-TRUE], [ACTION-IF-FALSE]) Run the compiler (and compilation flags) and the linker of the current language (*note Language Choice::) on the INPUT, run the shell commands ACTION-IF-TRUE on success, ACTION-IF-FALSE otherwise. If needed, ACTION-IF-TRUE can further access the just-linked program file ‘conftest$EXEEXT’. If INPUT is nonempty use the equivalent of ‘AC_LANG_CONFTEST(INPUT)’ to generate the current test source file; otherwise reuse the already-existing test source file. The INPUT can be made by ‘AC_LANG_PROGRAM’ and friends. The INPUT text is expanded as an unquoted here-document, so ‘$’, ‘`’ and some ‘\’s should be backslash-escaped. *Note Here-Documents::. ‘LDFLAGS’ and ‘LIBS’ are used for linking, in addition to the current compilation flags. It is customary to report unexpected failures with ‘AC_MSG_FAILURE’. This macro does not try to execute the program; use ‘AC_RUN_IFELSE’ if you need to do that (*note Runtime::). The ‘AC_LINK_IFELSE’ macro cannot be used for Erlang tests, since Erlang programs are interpreted and do not require linking.