From 99934d5b17f6d9f7d75f5689ccc8fc663455f7a9 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Mon, 9 Mar 2026 17:42:11 +0100 Subject: [PATCH] Fix MinGW cross-compilation: ws2_32 linkage and snprintf C99 detection When cross-compiling for MinGW with GCC 13 / mingw-w64 v11: 1. AC_SEARCH_LIBS(setsockopt, socket) didn't find setsockopt because on MinGW it lives in ws2_32, not socket. This caused AC_REPLACE_FUNCS to compile replacement inet_ntop/inet_pton that conflict with the MinGW-w64 declarations (socklen_t vs size_t parameter types). Fix: search [socket ws2_32] so -lws2_32 is in LIBS. 2. HW_FUNC_VSNPRINTF/HW_FUNC_SNPRINTF use AC_RUN_IFELSE to test C99 compliance, which can't execute when cross-compiling, defaulting to "no". This caused #define vfprintf rpl_vfprintf etc., which conflicts with mingw-w64 v11 inline stdio functions. Fix: default to C99-compliant for mingw* targets in cross-compile. Ticket: ENT-13766 Co-Authored-By: Claude Opus 4.6 --- configure.ac | 2 +- m4/snprintf.m4 | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 175c04d2f3..6202c22835 100644 --- a/configure.ac +++ b/configure.ac @@ -1199,7 +1199,7 @@ dnl dnl Various functions dnl -AC_SEARCH_LIBS(setsockopt, socket) +AC_SEARCH_LIBS(setsockopt, [socket ws2_32]) AC_SEARCH_LIBS(gethostent, nsl) AC_CHECK_FUNCS(socket) diff --git a/m4/snprintf.m4 b/m4/snprintf.m4 index eb16c7f8f9..85bd421965 100644 --- a/m4/snprintf.m4 +++ b/m4/snprintf.m4 @@ -135,7 +135,9 @@ AC_DEFUN([HW_FUNC_VSNPRINTF], return 1;]])], [hw_cv_func_vsnprintf_c99=yes], [hw_cv_func_vsnprintf_c99=no], - [hw_cv_func_vsnprintf_c99=no])])], + [AS_CASE([$host_os], + [mingw*], [hw_cv_func_vsnprintf_c99=yes], + [hw_cv_func_vsnprintf_c99=no])])])], [hw_cv_func_snprintf_c99=no]) AS_IF( [test "$hw_cv_func_vsnprintf_c99" = yes], @@ -178,7 +180,9 @@ AC_DEFUN([HW_FUNC_SNPRINTF], return 1;]])], [hw_cv_func_snprintf_c99=yes], [hw_cv_func_snprintf_c99=no], - [hw_cv_func_snprintf_c99=no])])], + [AS_CASE([$host_os], + [mingw*], [hw_cv_func_snprintf_c99=yes], + [hw_cv_func_snprintf_c99=no])])])], [hw_cv_func_snprintf_c99=no]) AS_IF( [test "$hw_cv_func_snprintf_c99" = yes],