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:
parent
522223c57c
commit
3433f631aa
1 changed files with 5 additions and 5 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue