@@ -120,15 +120,18 @@ ifneq ($(GGML_OPENCL_LIB),)
120120 LLAMA_LIBS += $(GGML_OPENCL_LIB )
121121endif
122122
123- # Default link libs. Windows is fully overridden in its branch below
124- # because -lpthread doesn't exist on MinGW (we use -lwinpthread instead)
125- # and -lz needs to sit after the static libs, not before.
123+ # Default link libs. -lz is appended to LIBS (not LDFLAGS) for every
124+ # platform that uses libcurl — libcurl references inflate*, and with
125+ # single-pass GNU ld + --as-needed, -lz must sit AFTER libcurl.a or
126+ # libz.so gets dropped from DT_NEEDED. glibc loaders happen to find
127+ # inflateEnd through the global namespace anyway; musl is strict and
128+ # fails dlopen with "Error relocating: inflateEnd: symbol not found".
126129ifeq ($(PLATFORM ) ,android)
127- LDFLAGS := -lz
130+ LDFLAGS :=
128131else ifeq ($(PLATFORM),windows)
129132 LDFLAGS :=
130133else
131- LDFLAGS := -lpthread -lz
134+ LDFLAGS := -lpthread
132135endif
133136
134137# ----------------------------------------------------------------------------
@@ -204,6 +207,7 @@ else ifeq ($(PLATFORM),android)
204207 LIBS += $(MBEDTLS_BUILD ) /library/libmbedtls.a
205208 LIBS += $(MBEDTLS_BUILD ) /library/libmbedx509.a
206209 LIBS += $(MBEDTLS_BUILD ) /library/libmbedcrypto.a
210+ LIBS += -lz
207211else
208212 # linux (default)
209213 EXT := so
214218 LIBS += $(MBEDTLS_BUILD ) /library/libmbedtls.a
215219 LIBS += $(MBEDTLS_BUILD ) /library/libmbedx509.a
216220 LIBS += $(MBEDTLS_BUILD ) /library/libmbedcrypto.a
221+ LIBS += -lz
217222endif
218223
219224# Vulkan / OpenCL runtime loaders. Must come AFTER the ggml-vulkan/-opencl
0 commit comments