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 += -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)