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.
This commit is contained in:
Graham McIntire 2026-01-30 13:24:25 -06:00
parent 522223c57c
commit 3433f631aa

View file

@ -10,15 +10,15 @@ UNAME_S := $(shell uname -s)
CFLAGS = -O3 -std=c99 -fPIC -Wall -Wextra -Wno-unused-parameter CFLAGS = -O3 -std=c99 -fPIC -Wall -Wextra -Wno-unused-parameter
CFLAGS += -I$(ERL_INCLUDE_PATH) CFLAGS += -I$(ERL_INCLUDE_PATH)
# Linker flags # Libraries (must come after source files in link command)
LDFLAGS = -lnetsnmp LIBS = -lnetsnmp
ifeq ($(UNAME_S),Darwin) ifeq ($(UNAME_S),Darwin)
# macOS specific flags # macOS specific flags
LDFLAGS += -dynamiclib -undefined dynamic_lookup CFLAGS += -dynamiclib -undefined dynamic_lookup
else else
# Linux flags # Linux flags
LDFLAGS += -shared CFLAGS += -shared
endif endif
# Target # Target
@ -31,7 +31,7 @@ all: $(TARGET)
$(TARGET): $(SRC) $(TARGET): $(SRC)
@mkdir -p ../priv @mkdir -p ../priv
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(CC) $(CFLAGS) -o $@ $< $(LIBS)
clean: clean:
rm -f $(TARGET) rm -f $(TARGET)