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 = -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)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue