Whamcloud - gitweb
Update shared library flags used for Apple/Darwin
authorTheodore Ts'o <tytso@mit.edu>
Thu, 18 Aug 2022 21:24:17 +0000 (17:24 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 18 Aug 2022 21:24:17 +0000 (17:24 -0400)
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 <tytso@mit.edu>
lib/Makefile.darwin-lib

index 95cdd4b..95e8ee0 100644 (file)
@@ -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) \