autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Location of declarations in Linux vs FreeBSD, etc.


From: Ralf Wildenhues
Subject: Re: Location of declarations in Linux vs FreeBSD, etc.
Date: Mon, 05 Mar 2007 20:27:31 +0100

Hello Philip,
* Philip Kovacs wrote on Mon, Mar 05, 2007 at 06:03:16AM CET:

Can anyone tell me how best to approach the problem of variation
of location of function declarations across OS'es?

I think the general answer is "it depends".  In the simplest case, you
can just include all headers that may be needed.  If not all headers
universally exist, then test for them and do the include only if
HAVE_HEADER. If the above approach works, then really you should use it.
The next more complicated case is with conflicting header files.
In that case I guess you should write a special test.  You can
use AC_COMPILE_IFELSE for general compile tests, and AC_CHECK_DECL
to find out if a symbol is declared.  You'll have to work around
the caching though if it really depends only on the set of included
headers (e.g., by unsetting the cache variable before the test).
Be sure to understand how the default includes provided by Autoconf
work (AC_INCLUDES_DEFAULT and the fourth argument to AC_CHECK_DECL)
and how to override it or append to it.
For example, in Linux the declaration for daemon() is in <unistd.h>,
but in FreeBSD it is in <stdlib.h>. In both cases, AC_CHECK_FUNCS([daemon]) has no problem finding daemon(), but I am interested defining a variable
so that the program can include (only) the correct header.

Why?
Is it possible to identify which header a function is located in, e.g.
given a list of possible headers?  Whats's the "right" way to handle this?

I think the right answer in this case is to just include both stdlib.h
and unistd.h.  If you care about portability to MinGW, then guard the
inclusion of the latter (and think how to work around the nonexistence
of daemon there ;-).
Useful doc bits:
<http://www.gnu.org/software/autoconf/manual/html_node/Default-Includes.html

<http://www.gnu.org/software/autoconf/manual/html_node/Header-Files.html>
Cheers,
Ralf




reply via email to

[Prev in Thread] Current Thread [Next in Thread]