Next: , Up: Header Files   [Contents][Index] Portability of Headers

This section documents some collected knowledge about common headers, and the problems they cause. By definition, this list always requires additions. A much more complete list is maintained by the Gnulib project (see Gnulib), covering Posix Headers in GNU gnulib and Glibc Headers in GNU gnulib. Please help us keep the gnulib list as complete as possible.

When we say that a header “may require” some set of other headers, we mean that it may be necessary for you to manually include those other headers first, or the contents of the header under test will fail to compile. When checking for these headers, you must provide the potentially-required headers in the includes argument to AC_CHECK_HEADER or AC_CHECK_HEADERS, or the check will fail spuriously. AC_INCLUDES_DEFAULT (see Default Includes) arranges to include a number of common requirements and should normally come first in your includes. For example, net/if.h may require sys/types.h, sys/socket.h, or both, and AC_INCLUDES_DEFAULT handles sys/types.h but not sys/socket.h, so you should check for it like this:

AC_CHECK_HEADERS([net/if.h], [], [],
# include <sys/socket.h>

Note that the example mixes single quoting (forAC_INCLUDES_DEFAULT, so that it gets expanded) and double quoting (to ensure that each preprocessor # gets treated as a literal string rather than a comment).


In C99 and later, limits.h defines LLONG_MIN, LLONG_MAX, and ULLONG_MAX, but many almost-C99 environments (e.g., default GCC 4.0.2 + glibc 2.4) do not define them.


This header file is obsolete; use string.h instead.


On some systems, this is the only header that declares strcasecmp, strncasecmp, and ffs.

This header may or may not include string.h for you. However, on all recent systems it is safe to include both string.h and strings.h, in either order, in the same source file.

inttypes.h vs. stdint.h

C99 specifies that inttypes.h includes stdint.h, so there’s no need to include stdint.h separately in a standard environment. However, some implementations have inttypes.h but not stdint.h (e.g., Solaris 7), and some have stdint.h but not inttypes.h (e.g. MSVC 2012). Therefore, it is necessary to check for each and include each only if available.


This header may require linux/types.h and/or sys/socket.h.


This header may require linux/types.h.


This header may require sys/types.h and/or sys/socket.h.


This header may require some combination of sys/types.h, sys/socket.h, netinet/in.h, and net/if.h.


This header may require sys/params.h.


This header may require sys/stream.h.


This header may require sys/types.h.


This header may require sys/types.h.


Using XFree86, this header requires X11/Xlib.h, which is probably so required that you might not even consider looking for it.

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