On Mon, 9 Jun 2025, Brian Inglis wrote:
> On 2025-06-09 15:56, Jeremy Drake via Cygwin-patches wrote:
> > > > an #ifndef cmsghdr with a comment about this situation? Or how do other
> > > > Cygwin headers handle potential conflicts with Windows headers?
> > > I appear to be missing where Mingw headers other than ntstatus.h are
> > > included
> > > in these Cygwin headers so how would Mingw version be defined here?
> >
> > Inside Cygwin, additional Windows headers are included, including winsock
> > headers to implement sockets within Cygwin.
>
> I understand that happens during the DLL build, but I am still not seeing
> where any of those nested header includes, whether __INSIDE_CYGWIN__ or not,
> includes any Mingw headers to define that version.
> So I do not believe any such fix should be applied here.
In file included from
/cygdrive/c/a/cygwin/cygwin/winsup/cygwin/include/cygwin/if.h:17,
from
/cygdrive/c/a/cygwin/cygwin/winsup/cygwin/include/ifaddrs.h:42,
from ../../../../winsup/cygwin/net.cc:26:
/cygdrive/c/a/cygwin/cygwin/winsup/cygwin/include/cygwin/socket.h:72:8:
error: redefinition of 'struct cmsghdr'
72 | struct cmsghdr
| ^~~~~~~
In file included from ../../../../winsup/cygwin/net.cc:21:
/usr/include/w32api/mswsock.h:174:18: note: previous definition of 'struct
cmsghdr'
174 | typedef struct _WSACMSGHDR {
| ^~~~~~~~~~~
> The conflict seems to be between the Mingw SIZE_T & INT definitions and the
> Cygwin size_t & int definitions used in the respective struct cmsghdr
> definitions.
My tweak to the submitted patch, which I don't presume to be correct but I
feel is safer than the version check, is
diff --git a/winsup/cygwin/include/cygwin/socket.h
b/winsup/cygwin/include/cygwin/socket.h
index 3a504d223c..6a71bb19a0 100644
--- a/winsup/cygwin/include/cygwin/socket.h
+++ b/winsup/cygwin/include/cygwin/socket.h
@@ -65,7 +65,9 @@ struct msghdr
int msg_flags; /* Received flags on recvmsg */
};
-#if __MINGW64_VERSION_MAJOR < 13
+/* Windows headers define struct cmsghdr via _WSACMSGHDR if
+ _WIN32_WINNT >= 0x0600, as of mingw-w64 v13 */
+#ifndef _WSACMSGHDR
struct cmsghdr
{