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.
39 lines
826 B
Makefile
39 lines
826 B
Makefile
# Makefile for building towerops_nif.so
|
|
|
|
# Erlang NIF paths
|
|
ERL_INCLUDE_PATH ?= $(shell erl -eval 'io:format("~s", [lists:concat([code:root_dir(), "/erts-", erlang:system_info(version), "/include"])])' -s init stop -noshell)
|
|
|
|
# Detect OS
|
|
UNAME_S := $(shell uname -s)
|
|
|
|
# Compiler flags
|
|
CFLAGS = -O3 -std=c99 -fPIC -Wall -Wextra -Wno-unused-parameter
|
|
CFLAGS += -I$(ERL_INCLUDE_PATH)
|
|
|
|
# Libraries (must come after source files in link command)
|
|
LIBS = -lnetsnmp
|
|
|
|
ifeq ($(UNAME_S),Darwin)
|
|
# macOS specific flags
|
|
CFLAGS += -dynamiclib -undefined dynamic_lookup
|
|
else
|
|
# Linux flags
|
|
CFLAGS += -shared
|
|
endif
|
|
|
|
# Target
|
|
TARGET = ../priv/towerops_nif.so
|
|
|
|
# Source files
|
|
SRC = towerops_nif.c
|
|
|
|
all: $(TARGET)
|
|
|
|
$(TARGET): $(SRC)
|
|
@mkdir -p ../priv
|
|
$(CC) $(CFLAGS) -o $@ $< $(LIBS)
|
|
|
|
clean:
|
|
rm -f $(TARGET)
|
|
|
|
.PHONY: all clean
|