In the GitHub CI, I now have builds that use the newest mingw (newer
than the latest mingw release, 14.0.0). In these builds, with the
gnulib modules
dfa stat timespec_get gethostname
I see a compilation error:
../../gllib/dfa.c:294:3: error: 'WCHAR' redeclared as different kind of symbol
294 | WCHAR, /* Only returned by lex. wctok
contains the
| ^~~~~
In file included from D:/a/_temp/msys64/mingw64/include/minwindef.h:163,
from D:/a/_temp/msys64/mingw64/include/windef.h:9,
from D:/a/_temp/msys64/mingw64/include/windows.h:69,
from D:/a/_temp/msys64/mingw64/include/winsock2.h:23,
from ./unistd.h:66,
from ./time.h:51,
from ./sys/stat.h:51,
from D:/a/_temp/msys64/mingw64/include/wchar.h:19,
from ./wchar.h:77,
from D:/a/_temp/msys64/mingw64/include/uchar.h:28,
from ./uchar.h:45,
from ../../gllib/localeinfo.h:20,
from ../../gllib/dfa.c:41:
D:/a/_temp/msys64/mingw64/include/winnt.h:320:19: note: previous declaration of
'WCHAR' with type 'WCHAR' {aka 'short unsigned int'}
320 | typedef wchar_t WCHAR;
| ^~~~~
make[4]: *** [Makefile:3048: dfa.o] Error 1
It's the consequence of namespace pollution (inclusion of <windows.h>),
triggered by mingw-w64 commit 732b63491391721299cf8e30e641df9d03ad322e from
2026-08-19:
https://github.com/mingw-w64/mingw-w64/commit/732b63491391721299cf8e30e641df9d03ad322e
This patch provides a workaround, by adjusting the older commit from
https://lists.gnu.org/archive/html/bug-gnulib/2019-11/msg00024.html
2026-09-04 Bruno Haible <[email protected]>
time-h: Fix compilation error in dfa.c on mingw.
* lib/time.in.h: Instead of including <unistd.h>, define
_POSIX_THREAD_SAFE_FUNCTIONS.
diff --git a/lib/time.in.h b/lib/time.in.h
index 5bbccf7662..2f470dd4cc 100644
--- a/lib/time.in.h
+++ b/lib/time.in.h
@@ -45,9 +45,11 @@
# define _@GUARD_PREFIX@_TIME_H
/* mingw's <time.h> provides the functions asctime_r, ctime_r, gmtime_r,
- localtime_r only if <unistd.h> or <pthread.h> has been included before. */
+ localtime_r only if <unistd.h> or <pthread.h> has been included before
+ or if _POSIX_THREAD_SAFE_FUNCTIONS is defined. */
# if defined __MINGW32__
-# include <unistd.h>
+# undef _POSIX_THREAD_SAFE_FUNCTIONS
+# define _POSIX_THREAD_SAFE_FUNCTIONS 200112L
# endif
# @INCLUDE_NEXT@ @NEXT_TIME_H@