Since commit 4e86671a, gethostname failed to compile on mingw. Gnulib's sys/socket.h includes winsock2.h, which then includes unistd.h prior to declaring gethostname. Therefore, unistd.h cannot replace gethostname until winsock2.h is complete.
* lib/sys_socket.in.h (includes): Set witness when including winsock2.h. * lib/unistd.in.h (includes): Don't replace anything when included by winsock2.h. Reported by Matthias Bolte. Signed-off-by: Eric Blake <ebl...@redhat.com> --- Thanks to Matthias for doing the git bisect to narrow down the cause of his error: # i686-pc-mingw32-gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -MT sockets.o -MD -MP -MF -deps/sockets.Tpo -c -o sockets.o sockets.c In file included from ./sys/socket.h:389, from sockets.h:37, from sockets.c:23: /usr/i686-pc-mingw32/sys-root/mingw/include/winsock2.h:635: error: conflicting types for 'rpl_gethostname' ./unistd.h:824: note: previous declaration of 'rpl_gethostname' was here I believe this will solve the issue, but would appreciate some testing by Matthias. I also think that this is the same issue as: http://lists.gnu.org/archive/html/bug-gnulib/2010-01/msg00183.html ChangeLog | 9 +++++++++ lib/sys_socket.in.h | 7 ++++++- lib/unistd.in.h | 3 ++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index df8b7a6..71be18e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2010-03-19 Eric Blake <ebl...@redhat.com> + + gethostname: fix build on mingw + * lib/sys_socket.in.h (includes): Set witness when including + winsock2.h. + * lib/unistd.in.h (includes): Don't replace anything when included + by winsock2.h. + Reported by Matthias Bolte. + 2010-02-17 Eric Blake <e...@byu.net> manywarnings: add more warnings diff --git a/lib/sys_socket.in.h b/lib/sys_socket.in.h index 006a901..b34b506 100644 --- a/lib/sys_socket.in.h +++ b/lib/sys_socket.in.h @@ -28,7 +28,10 @@ - On Cygwin 1.5.x we have a sequence of nested includes <sys/socket.h> -> <cygwin/socket.h> -> <asm/socket.h> -> <cygwin/if.h>, and the latter includes <sys/socket.h>. In this situation, the functions - are not yet declared, therefore we cannot provide the C++ aliases. */ + are not yet declared, therefore we cannot provide the C++ aliases. + - On mingw, <sys/socket.h> -> <winsock2.h> -> <unistd.h>, and the latter + includes <winsock2.h>. In this situation, functions like gethostname + are not yet declared, therefore we must defer. */ #...@include_next@ @NEXT_SYS_SOCKET_H@ @@ -129,7 +132,9 @@ struct sockaddr_storage # if @HAVE_WINSOCK2_H@ +# define _GL_INCLUDING_WINSOCK2_H # include <winsock2.h> +# undef _GL_INCLUDING_WINSOCK2_H # endif # if @HAVE_WS2TCPIP_H@ # include <ws2tcpip.h> diff --git a/lib/unistd.in.h b/lib/unistd.in.h index 68e1a87..c8d4339 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -26,7 +26,8 @@ # @INCLUDE_NEXT@ @NEXT_UNISTD_H@ #endif -#ifndef _GL_UNISTD_H +/* See sys_socket.in.h for mingw workaround. */ +#if !defined _GL_UNISTD_H && !defined _GL_INCLUDING_WINSOCK2_H #define _GL_UNISTD_H /* NetBSD 5.0 mis-defines NULL. Also get size_t. */ -- 1.6.6.1