When building for target i686-pc-mingw32 on host (Debian) i686-pc-linux-gnu I find the file /opt/build/gcc-4.1.2/libiberty/pex-win32.c uses both #include "pex-common.h" and "#include <windows.h>" thus we get this:
In file included from /opt/mingw32/i686-pc-mingw32/sys-include/bits/resource.h:151, from /opt/mingw32/i686-pc-mingw32/sys-include/sys/resource.h:26, from /opt/mingw32/i686-pc-mingw32/sys-include/sys/wait.h:32, from /opt/build/gcc-4.1.2/libiberty/pex-win32.c:37: /opt/mingw32/i686-pc-mingw32/sys-include/bits/time.h:70: error: redefinition of 'struct timeval' Creating an ".i" file I see this: # 181 "/opt/build/gcc-4.1.2/libiberty/../include/libiberty.h" /* Get the current time. */ /* Prototypes vary from system to system, so we only provide a prototype on systems where we know that we need it. */ #ifdef __MINGW32__ /* Forward declaration to avoid #include <sys/time.h>. */ struct timeval; extern int gettimeofday (struct timeval *, void *); #endif # 109 "/opt/mingw32/i686-pc-mingw32/include/winsock2.h" 3 struct timeval { long tv_sec; long tv_usec; }; # 69 "/opt/mingw32/i686-pc-mingw32/sys-include/bits/time.h" struct timeval { __time_t tv_sec; __suseconds_t tv_usec; }; The file "sys/resource.h" includes "bits/resource.h", which then includes "bits/time.h" _directly_. The file "sys/time.h" has an ifdef system like this: #ifndef _TIMEVAL_DEFINED /* also in winsock[2].h */ #define _TIMEVAL_DEFINED struct timeval { long tv_sec; long tv_usec; }; ... #endif /* _TIMEVAL_DEFINED */ The file "bits/time.h" has an ifdef system like this: /* Never include this file directly; use <time.h> instead. */ #ifdef __need_timeval # undef __need_timeval # ifndef _STRUCT_TIMEVAL # define _STRUCT_TIMEVAL # include <bits/types.h> /* A time value that is accurate to the nearest microsecond but also has a range of years. */ struct timeval { __time_t tv_sec; /* Seconds. */ __suseconds_t tv_usec; /* Microseconds. */ }; # endif /* struct timeval */ #endif /* need timeval */ Since we are compiling for --target=i686-pc-mingw32 I imagine we prefer the winsock2.h version of struct timeval. To achieve that do this: /opt/build/gcc-4.1.2/libiberty/pex-win32.c ----- OLD #include "pex-common.h" #include <windows.h> #ifdef HAVE_STDLIB_H ----- ----- NEW #include "pex-common.h" #include <windows.h> #ifdef __MINGW32__ /* avoid redefinition of 'struct timeval' */ #define _STRUCT_TIMEVAL #endif #ifdef HAVE_STDLIB_H ----- Alternately we could do this: /opt/build/gcc-4.1.2/include/libiberty.h ----- OLD /* Get the current time. */ /* Prototypes vary from system to system, so we only provide a prototype on systems where we know that we need it. */ #ifdef __MINGW32__ /* Forward declaration to avoid #include <sys/time.h>. */ struct timeval; extern int gettimeofday (struct timeval *, void *); #endif ----- ----- NEW /* Get the current time. */ /* Prototypes vary from system to system, so we only provide a prototype on systems where we know that we need it. */ #ifdef __MINGW32__ /* Forward declaration to avoid #include <sys/time.h>. */ struct timeval; extern int gettimeofday (struct timeval *, void *); #define _STRUCT_TIMEVAL /* use winsock2.h timeval structure instead of bits/time.h version */ #endif ----- Which do the maintainers prefer ? Either way pex-win32.c compiles without error. I chose to modify /opt/build/gcc-4.1.2/include/libiberty.h for _my_ build since there was already a "#ifdef __MINGW32__" in that file. I don't know that "sys/resource.h" which includes "bits/resource.h" should include "bits/time.h" _directly_. I don't know why the "bits/time.h" says this: "/* Never include this file directly; use <time.h> instead. */" since "time.h" does not include "bits/time.h" - so "bits/resource.h" needs to if it wants bits/time.h. The files "bits/resource.h" and "sys/select.h" are the only ones that include "bits/time.h", that may not be GCC's fault but I am using GNU/Linux. # grep -r bits\/time.h /opt/mingw32/i686-pc-mingw32/sys-include/* /opt/mingw32/i686-pc-mingw32/sys-include/bits/resource.h:#include <bits/time.h> /* For `struct timeval'. */ Binary file /opt/mingw32/i686-pc-mingw32/sys-include/c++/4.2/bits/stdc++.h.gch/O0g.gch matches Binary file /opt/mingw32/i686-pc-mingw32/sys-include/c++/4.2/bits/stdc++.h.gch/O2g.gch matches Binary file /opt/mingw32/i686-pc-mingw32/sys-include/c++/4.2/bits/stdtr1c++.h.gch/O2g.gch matches /opt/mingw32/i686-pc-mingw32/sys-include/sys/select.h:#include <bits/time.h> If it is agreed that this is a bug then you will want to update http://ftp.gnu.org/gnu/gcc/gcc-4.1.2/gcc-core-4.1.2.tar.bz2 -- Summary: struct timeval collision in include files for MinGW cross compile Product: gcc Version: 4.1.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: bootstrap AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: rob1weld at aol dot com GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-mingw32 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32474