Node:Examining Libraries, Next:, Previous:Examining Syntax, Up:Writing Tests



Examining Libraries

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.

A few systems have linkers that do not return a failure exit status when there are unresolved functions in the link. This bug makes the configuration scripts produced by Autoconf unusable on those systems. However, some of them can be given options that make the exit status correct. This is a problem that Autoconf does not currently handle automatically. If users encounter this problem, they might be able to solve it by setting LDFLAGS in the environment to pass whatever options the linker needs (for example, -Wl,-dn on MIPS RISC/OS).

AC_TRY_LINK 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 (see Libraries), by adding the library being checked for to LIBS temporarily and trying to link a small program.

AC_TRY_LINK (includes, function-body, [action-if-found], [action-if-not-found]) Macro
Depending on the current language (see Language Choice), create a test program to see whether a function whose body consists of function-body can be compiled and linked. If the file compiles and links successfully, run shell commands action-if-found, otherwise run action-if-not-found.

This macro double quotes both includes and function-body.

For C and C++, includes is any #include statements needed by the code in function-body (includes will be ignored if the currently selected language is Fortran 77). This macro also uses CFLAGS or CXXFLAGS if either C or C++ is the currently selected language, as well as CPPFLAGS, when compiling. If Fortran 77 is the currently selected language then FFLAGS will be used when compiling. However, both LDFLAGS and LIBS will be used during linking in all cases.

AC_TRY_LINK_FUNC (function, [action-if-found], [action-if-not-found]) Macro
Depending on the current language (see Language Choice), create a test program to see whether a program whose body consists of a prototype of and a call to function can be compiled and linked.

If the file compiles and links successfully, run shell commands action-if-found, otherwise run action-if-not-found.