From 558146c31d341faae62237eafc0c260bd785a2d7 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Thu, 18 Aug 2022 17:24:17 -0400 Subject: [PATCH] Update shared library flags used for Apple/Darwin As submitted by Carlos Cabrera: We need to set the `-install_name` flag so that library consumers can find the linked libraries when installed outside the default dyld search path. This is the case, for example, when installed using the Homebrew package manager on Apple Silicon. I've removed the `-flat_namespace` flag because this flag is effectively deprecated, and can cause issues when using `dlopen` [1]. We also need to change `-undefined warning` to `-undefined dynamic_lookup`, since the former flag is not supported without `-flat_namespace`. Using `-undefined dynamic_lookup` instructs the dynamic loader to resolve undefined symbols at run/load-time. These are the flags used by Libtool on the newest versions of macOS, and we've applied similar patches to many other packages at Homebrew without any issues. [1] https://developer.apple.com/forums/thread/689991 Signed-off-by: Theodore Ts'o --- lib/Makefile.darwin-lib | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Makefile.darwin-lib b/lib/Makefile.darwin-lib index 95cdd4b..95e8ee0 100644 --- a/lib/Makefile.darwin-lib +++ b/lib/Makefile.darwin-lib @@ -24,7 +24,8 @@ image: $(BSD_LIB) $(BSD_LIB): $(OBJS) $(E) " GEN_BSD_SOLIB $(BSD_LIB)" $(Q) (cd pic; $(CC) -dynamiclib -compatibility_version 1.0 -current_version $(BSDLIB_VERSION) \ - -flat_namespace -undefined warning -o $(BSD_LIB) $(OBJS)) + -install_name $(BSDLIB_INSTALL_DIR)/$(BSD_LIB) \ + -undefined dynamic_lookup -o $(BSD_LIB) $(OBJS)) $(Q) $(MV) pic/$(BSD_LIB) . $(Q) $(RM) -f ../$(BSD_LIB) $(Q) (cd ..; $(LN) $(LINK_BUILD_FLAGS) \ -- 1.8.3.1