I got this failure on cygwin, when building m4 with -DGNULIB_POSIXCHECK (m4 does not use the getsubopt module):
gcc -std=gnu99 -I. -I../../lib -I/cygdrive/c/cygwin/usr/local/include - DGNULIB_POSIXCHECK=1 -MT gl_avltree_oset.o -MD -MP - MF .deps/gl_avltree_oset.Tpo -c -o gl_avltree_oset.o ../../lib/gl_avltree_oset.c In file included from /usr/include/unistd.h:4, from ./unistd.h:27, from ./stdlib.h:310, from ../../lib/gl_avltree_oset.c:23: /usr/include/sys/unistd.h:172: error: parse error before "void" That line in the system header is: int getsubopt(char **, char * const *, char **); It turns out that our replacement stdlib.h was including <unistd.h> after it had already defined getsubopt into a macro, so the macro then interfered with the cygwin header's attempts to declare getsubopt. Yet another reason why my proposed warn-on-use idiom will be nicer (no macro collisions with system declarations), although that is running into some implementation snags (AC_CHECK_DECLS_ONCE only works for the default headers of AC_INCLUDES_DEFAULT, but I want to minimize decl checks for other headers such as math.h). From: Eric Blake <e...@byu.net> Date: Mon, 21 Dec 2009 11:14:18 -0700 Subject: [PATCH] stdlib: ensure system headers are complete before overriding On cygwin, compiling with -DGNULIB_POSIXCHECK failed because the getsubopt link warning definition interfered with the inclusion of the system header. The fix, as always in these types of problems, is to ensure that system headers are completely included before doing any overrides. * lib/stdlib.in.h (includes): Move unistd inclusion sooner, to avoid conflicting with system getsubopt. Signed-off-by: Eric Blake <e...@byu.net> --- ChangeLog | 6 ++++++ lib/stdlib.in.h | 8 +++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index c2ae54c..4128c26 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2009-12-21 Eric Blake <e...@byu.net> + + stdlib: ensure system headers are complete before overriding + * lib/stdlib.in.h (includes): Move unistd inclusion sooner, to + avoid conflicting with system getsubopt. + 2009-12-21 Eric Blake <e...@byu.net> warn-on-use: use instead of link-warning diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h index af9c35e..39782d2 100644 --- a/lib/stdlib.in.h +++ b/lib/stdlib.in.h @@ -66,6 +66,11 @@ struct random_data }; #endif +#if @GNULIB_MKSTEMP@ +/* On MacOS X 10.3, only <unistd.h> declares mkstemp. */ +# include <unistd.h> +#endif + /* The definition of GL_LINK_WARNING is copied here. */ /* The definition of _GL_ARG_NONNULL is copied here. */ @@ -266,9 +271,6 @@ extern int mkostemps (char * /*template*/, int /*suffixlen*/, int /*flags*/) set. */ # define mkstemp rpl_mkstemp extern int mkstemp (char * /*template*/) _GL_ARG_NONNULL ((1)); -# else -/* On MacOS X 10.3, only <unistd.h> declares mkstemp. */ -# include <unistd.h> # endif #elif defined GNULIB_POSIXCHECK # undef mkstemp -- 1.6.4.2