From 45bc2518bed20b1bab4e71afb13feba0e4aeb205 Mon Sep 17 00:00:00 2001 From: Michael Partridge Date: Fri, 20 Mar 2026 14:30:20 +1030 Subject: [PATCH] configure: support z.lib and zlib.lib for zlib on MSVC-style linkers Probe the zlib pkg-config link flags to detect whether the Windows import library is named z.lib or zlib.lib, and use that when rewriting -lz for MSVC-style linkers. Also make the non-pkg-config zlib fallback try both names explicitly so configure works with either z.lib or zlib.lib. --- configure | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/configure b/configure index b9b8e51dc0..21128a80a0 100755 --- a/configure +++ b/configure @@ -835,6 +835,10 @@ is_in(){ return 1 } +msvc_style_linker(){ + is_in $ld_type msvc icl lld-link +} + # The cfg loop is very hot (several thousands iterations), and in bash also # potentially quite slow. Try to abort the iterations early, preferably without # calling functions. 70%+ of the time cfg is already done or without deps. @@ -1672,6 +1676,32 @@ check_pkg_config(){ eval add_cflags \$${name}_cflags } +probe_msvc_zlib_libname(){ + log probe_msvc_zlib_libname + zlib_msvc_lib=zlib.lib + + msvc_style_linker || return 0 + test_cmd $pkg_config --exists --print-errors zlib || return 0 + + zlib_pkg_libs=$($pkg_config --libs $pkg_config_flags zlib) || return 0 + is_in -lz $zlib_pkg_libs || return 0 + + for zlib_pkg_lib in $zlib_pkg_libs; do + case $zlib_pkg_lib in + -L*) + zlib_pkg_libdir=${zlib_pkg_lib#-L} + if test -f "$zlib_pkg_libdir/z.lib"; then + zlib_msvc_lib=z.lib + return 0 + elif test -f "$zlib_pkg_libdir/zlib.lib"; then + zlib_msvc_lib=zlib.lib + return 0 + fi + ;; + esac + done +} + check_pkg_config_cpp(){ log check_pkg_config_cpp "$@" name="$1" @@ -5201,7 +5231,7 @@ msvc_common_flags(){ -mthumb) ;; -march=*) ;; -mfp16-format=*) ;; - -lz) echo zlib.lib ;; + -lz) echo ${zlib_msvc_lib:-zlib.lib} ;; -lx264) echo libx264.lib ;; -lstdc++) ;; -l*) echo ${flag#-l}.lib ;; @@ -7240,8 +7270,10 @@ if ! disabled pthreads && ! enabled w32threads && ! enabled os2threads; then fi fi +enabled zlib && msvc_style_linker && probe_msvc_zlib_libname enabled zlib && { check_pkg_config zlib zlib "zlib.h" zlibVersion || - check_lib zlib zlib.h zlibVersion -lz; } + { zlib_msvc_lib=z.lib; check_lib zlib zlib.h zlibVersion -lz; } || + { zlib_msvc_lib=zlib.lib; check_lib zlib zlib.h zlibVersion -lz; }; } enabled bzlib && check_lib bzlib bzlib.h BZ2_bzlibVersion -lbz2 enabled lzma && check_lib lzma lzma.h lzma_version_number -llzma