Skip to content

Commit 04649a1

Browse files
KimYannnclaude
andcommitted
build: unify static/dynamic linking across Linux and macOS
Replace the platform-specific linking logic (Linux: -static full static binary; macOS: .a preferred with -l fallback) with a single unified approach that works everywhere: - Search for .a static archives in LIBRARY_DIRS and common paths - If found, link the .a directly (static) - If not found, fallback to -l (dynamic) This removes the -static flag on Linux which required a static glibc and broke builds in package managers like conda where only shared system libraries are available. Behavior is unchanged when static archives exist (e.g., user-compiled libs). When only shared libs are available (conda, apt, etc.), the build now succeeds instead of failing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent fcf9166 commit 04649a1

1 file changed

Lines changed: 10 additions & 15 deletions

File tree

Makefile

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,16 @@ CXX ?= g++
1818
CXXFLAGS := -std=c++11 -pthread -g -O3 -MD -MP -I. -I${DIR_INC} $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir)) ${CXXFLAGS}
1919
LIBS := -lisal -ldeflate -lhwy -lpthread
2020

21-
UNAME_S := $(shell uname -s)
22-
ifeq ($(UNAME_S),Linux)
23-
# Linux: fully static binary
24-
LD_FLAGS := $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) -static -Wl,--no-as-needed -pthread $(LIBS) $(LD_FLAGS)
25-
else
26-
# macOS: link 3rd-party libs statically via .a when available, fallback to dynamic
27-
FIND_STATIC = $(firstword $(foreach d,$(LIBRARY_DIRS),$(wildcard $(d)/lib$(1).a)) $(wildcard /usr/local/lib/lib$(1).a /opt/homebrew/lib/lib$(1).a))
28-
STATIC_LIBS :=
29-
DYNAMIC_LIBS :=
30-
$(foreach lib,isal deflate hwy,\
31-
$(if $(call FIND_STATIC,$(lib)),\
32-
$(eval STATIC_LIBS += $(call FIND_STATIC,$(lib))),\
33-
$(eval DYNAMIC_LIBS += -l$(lib))))
34-
LD_FLAGS := $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) $(STATIC_LIBS) $(DYNAMIC_LIBS) -lpthread $(LD_FLAGS)
35-
endif
21+
# Link 3rd-party libs statically via .a when available, fallback to -l dynamic.
22+
# This works across Linux, macOS, and package managers (conda, brew, etc.).
23+
FIND_STATIC = $(firstword $(foreach d,$(LIBRARY_DIRS),$(wildcard $(d)/lib$(1).a)) $(wildcard /usr/local/lib/lib$(1).a /opt/homebrew/lib/lib$(1).a))
24+
STATIC_LIBS :=
25+
DYNAMIC_LIBS :=
26+
$(foreach lib,isal deflate hwy,\
27+
$(if $(call FIND_STATIC,$(lib)),\
28+
$(eval STATIC_LIBS += $(call FIND_STATIC,$(lib))),\
29+
$(eval DYNAMIC_LIBS += -l$(lib))))
30+
LD_FLAGS := $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) $(STATIC_LIBS) $(DYNAMIC_LIBS) -lpthread $(LD_FLAGS)
3631

3732

3833
${BIN_TARGET}:${OBJ}

0 commit comments

Comments
 (0)