From c36690c56c6a99130e639582b4df1c997d602821 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Wed, 4 Sep 2024 23:05:42 +0800 Subject: [PATCH] Fix libsvm name for Darwin On macOS, shared libraries are expected to be installed with the naming convention lib$NAME.$SOVERSION.dylib We also prefix the library install name with `@rpath` to indicate to the dynamic linker that it should use RPATH to look for `libsvm`. Without this, the dynamic linker will only search the calling process' current working directory, which will, in general, not contain `libsvm`. --- Makefile | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 1bc5d4e5..a8239424 100644 --- a/Makefile +++ b/Makefile @@ -3,9 +3,11 @@ CFLAGS = -Wall -Wconversion -O3 -fPIC SHVER = 4 OS = $(shell uname) ifeq ($(OS),Darwin) - SHARED_LIB_FLAG = -dynamiclib -Wl,-install_name,libsvm.so.$(SHVER) + LIB_NAME = libsvm.$(SHVER).dylib + SHARED_LIB_FLAG = -dynamiclib -Wl,-install_name,@rpath/$(LIB_NAME) else - SHARED_LIB_FLAG = -shared -Wl,-soname,libsvm.so.$(SHVER) + LIB_NAME = libsvm.so.$(SHVER) + SHARED_LIB_FLAG = -shared -Wl,-soname,$(LIB_NAME) endif # Uncomment the following lines to enable parallelization with OpenMP @@ -15,7 +17,7 @@ endif all: svm-train svm-predict svm-scale lib: svm.o - $(CXX) $(SHARED_LIB_FLAG) svm.o -o libsvm.so.$(SHVER) + $(CXX) $(SHARED_LIB_FLAG) svm.o -o $(LIB_NAME) svm-predict: svm-predict.c svm.o $(CXX) $(CFLAGS) svm-predict.c svm.o -o svm-predict -lm svm-train: svm-train.c svm.o @@ -25,4 +27,4 @@ svm-scale: svm-scale.c svm.o: svm.cpp svm.h $(CXX) $(CFLAGS) -c svm.cpp clean: - rm -f *~ svm.o svm-train svm-predict svm-scale libsvm.so.$(SHVER) + rm -f *~ svm.o svm-train svm-predict svm-scale $(LIB_NAME)