From 3433f631aa4fdee1badb78d8ac44126b711fc3e8 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Fri, 30 Jan 2026 13:24:25 -0600 Subject: [PATCH] fix: correct library linking order in Makefile Move -lnetsnmp to end of link command (after source files). In GCC/Clang, library flags must come after the object files that reference them for proper symbol resolution. This fixes 'undefined symbol: init_snmp' runtime errors on Linux. --- c_src/Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/c_src/Makefile b/c_src/Makefile index 462f899d..9d7b12d5 100644 --- a/c_src/Makefile +++ b/c_src/Makefile @@ -10,15 +10,15 @@ UNAME_S := $(shell uname -s) CFLAGS = -O3 -std=c99 -fPIC -Wall -Wextra -Wno-unused-parameter CFLAGS += -I$(ERL_INCLUDE_PATH) -# Linker flags -LDFLAGS = -lnetsnmp +# Libraries (must come after source files in link command) +LIBS = -lnetsnmp ifeq ($(UNAME_S),Darwin) # macOS specific flags - LDFLAGS += -dynamiclib -undefined dynamic_lookup + CFLAGS += -dynamiclib -undefined dynamic_lookup else # Linux flags - LDFLAGS += -shared + CFLAGS += -shared endif # Target @@ -31,7 +31,7 @@ all: $(TARGET) $(TARGET): $(SRC) @mkdir -p ../priv - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< + $(CC) $(CFLAGS) -o $@ $< $(LIBS) clean: rm -f $(TARGET)