gpt4 book ai didi

macos - 我的目标与 brew 中的库动态链接。如何捆绑分发?

转载 作者:行者123 更新时间:2023-12-04 20:29:50 25 4
gpt4 key购买 nike

我构建了一个音频插件。我的目标 .app.component .

我动态链接到 brew 安装的库,libfluidsynth .

我复制了 libfluidsynth.app/.component .
我用过 install_name_tool重新链接二进制文件以指向捆绑的 libfluidsynth .
libfluidsynth取决于 glib , gthread , intl .
我将这些库复制到包中,重新链接 libfluidsynth更喜欢捆绑的副本。
我也对这些库及其依赖项做了同样的事情。

快速浏览一下它的外观:

ls /Users/me/git/juicysfplugin/Builds/MacOSX/build/Release/juicysfplugin.app/Contents/Frameworks
libfluidsynth.1.7.1.dylib
libglib-2.0.0.dylib
libgthread-2.0.0.dylib
libintl.8.dylib
libpcre.1.dylib

otool -L \
/Users/me/git/juicysfplugin/Builds/MacOSX/build/Release/juicysfplugin.app/Contents/MacOS/juicysfplugin \
/Users/me/git/juicysfplugin/Builds/MacOSX/build/Release/juicysfplugin.app/Contents/Frameworks/* \
| grep -vE '\t(/System/Library|/usr/lib)'

/Users/me/git/juicysfplugin/Builds/MacOSX/build/Release/juicysfplugin.app/Contents/MacOS/juicysfplugin:
@executable_path/../Frameworks/libfluidsynth.1.7.1.dylib (compatibility version 1.0.0, current version 1.7.1)
/Users/me/git/juicysfplugin/Builds/MacOSX/build/Release/juicysfplugin.app/Contents/Frameworks/libfluidsynth.1.7.1.dylib:
@loader_path/../Frameworks/libfluidsynth.1.dylib (compatibility version 1.0.0, current version 1.7.1)
@loader_path/../Frameworks/libgthread-2.0.0.dylib (compatibility version 5401.0.0, current version 5401.3.0)
@loader_path/../Frameworks/libglib-2.0.0.dylib (compatibility version 5401.0.0, current version 5401.3.0)
@loader_path/../Frameworks/libintl.8.dylib (compatibility version 10.0.0, current version 10.5.0)
/Users/me/git/juicysfplugin/Builds/MacOSX/build/Release/juicysfplugin.app/Contents/Frameworks/libglib-2.0.0.dylib:
@loader_path/../Frameworks/libglib-2.0.0.dylib (compatibility version 5401.0.0, current version 5401.3.0)
@loader_path/../Frameworks/libpcre.1.dylib (compatibility version 4.0.0, current version 4.9.0)
@loader_path/../Frameworks/libintl.8.dylib (compatibility version 10.0.0, current version 10.5.0)
/Users/me/git/juicysfplugin/Builds/MacOSX/build/Release/juicysfplugin.app/Contents/Frameworks/libgthread-2.0.0.dylib:
@loader_path/../Frameworks/libgthread-2.0.0.dylib (compatibility version 5401.0.0, current version 5401.3.0)
@loader_path/../Frameworks/libglib-2.0.0.dylib (compatibility version 5401.0.0, current version 5401.3.0)
@loader_path/../Frameworks/libpcre.1.dylib (compatibility version 4.0.0, current version 4.9.0)
@loader_path/../Frameworks/libintl.8.dylib (compatibility version 10.0.0, current version 10.5.0)
/Users/me/git/juicysfplugin/Builds/MacOSX/build/Release/juicysfplugin.app/Contents/Frameworks/libintl.8.dylib:
@loader_path/../Frameworks/libintl.8.dylib (compatibility version 10.0.0, current version 10.5.0)
/Users/me/git/juicysfplugin/Builds/MacOSX/build/Release/juicysfplugin.app/Contents/Frameworks/libpcre.1.dylib:
@loader_path/../Frameworks/libpcre.1.dylib (compatibility version 4.0.0, current version 4.9.0)

这对 .app 非常有效 .在这里,查看打开的文件( opensnoop | grep 'dylib' ):
EXECNAME      PATH
juicysfplugin juicysfplugin.app/Contents/MacOS/../Frameworks/libfluidsynth.1.7.1.dylib
juicysfplugin juicysfplugin.app/Contents/MacOS/../Frameworks/../Frameworks/libgthread-2.0.0.dylib
juicysfplugin juicysfplugin.app/Contents/MacOS/../Frameworks/../Frameworks/libglib-2.0.0.dylib
juicysfplugin juicysfplugin.app/Contents/MacOS/../Frameworks/../Frameworks/libintl.8.dylib
juicysfplugin juicysfplugin.app/Contents/MacOS/../Frameworks/../Frameworks/../Frameworks/libpcre.1.dylib
.app仅在其捆绑的 Frameworks 文件夹中查找 dylib。完美的。

然后我在我的 .component 上做了同样的复制和重新链接。目标。 这没有用。

我加载了 .component进入音频插件主机,并检查文件打开:
EXECNAME     PATH
Plugin Host /Users/me/Library/Audio/Plug-Ins/Components/juicysfplugin.component/Contents/MacOS/juicysfplugin
Plugin Host /usr/local/lib/libfluidsynth.1.7.1.dylib
Plugin Host /usr/local/opt/glib/lib/libgthread-2.0.0.dylib
Plugin Host /usr/local/opt/glib/lib/libglib-2.0.0.dylib
Plugin Host /usr/local/opt/gettext/lib/libintl.8.dylib
Plugin Host /usr/local/opt/pcre/lib/libpcre.1.dylib

它正在寻找 /usr/local 下的图书馆.为什么?作为健全性检查,我使用了 otool确认我确实链接正确:
otool -L \
/Users/me/Library/Audio/Plug-Ins/Components/juicysfplugin.component/Contents/MacOS/juicysfplugin \
/Users/me/Library/Audio/Plug-Ins/Components/juicysfplugin.component/Contents/Frameworks/* \
| grep -vE '\t(/System/Library|/usr/lib)'

/Users/me/Library/Audio/Plug-Ins/Components/juicysfplugin.component/Contents/MacOS/juicysfplugin:
@executable_path/../Frameworks/libfluidsynth.1.7.1.dylib (compatibility version 1.0.0, current version 1.7.1)
/Users/me/Library/Audio/Plug-Ins/Components/juicysfplugin.component/Contents/Frameworks/libfluidsynth.1.7.1.dylib:
@loader_path/../Frameworks/libfluidsynth.1.dylib (compatibility version 1.0.0, current version 1.7.1)
@loader_path/../Frameworks/libgthread-2.0.0.dylib (compatibility version 5401.0.0, current version 5401.3.0)
@loader_path/../Frameworks/libglib-2.0.0.dylib (compatibility version 5401.0.0, current version 5401.3.0)
@loader_path/../Frameworks/libintl.8.dylib (compatibility version 10.0.0, current version 10.5.0)
/Users/me/Library/Audio/Plug-Ins/Components/juicysfplugin.component/Contents/Frameworks/libglib-2.0.0.dylib:
@loader_path/../Frameworks/libglib-2.0.0.dylib (compatibility version 5401.0.0, current version 5401.3.0)
@loader_path/../Frameworks/libpcre.1.dylib (compatibility version 4.0.0, current version 4.9.0)
@loader_path/../Frameworks/libintl.8.dylib (compatibility version 10.0.0, current version 10.5.0)
/Users/me/Library/Audio/Plug-Ins/Components/juicysfplugin.component/Contents/Frameworks/libgthread-2.0.0.dylib:
@loader_path/../Frameworks/libgthread-2.0.0.dylib (compatibility version 5401.0.0, current version 5401.3.0)
@loader_path/../Frameworks/libglib-2.0.0.dylib (compatibility version 5401.0.0, current version 5401.3.0)
@loader_path/../Frameworks/libpcre.1.dylib (compatibility version 4.0.0, current version 4.9.0)
@loader_path/../Frameworks/libintl.8.dylib (compatibility version 10.0.0, current version 10.5.0)
/Users/me/Library/Audio/Plug-Ins/Components/juicysfplugin.component/Contents/Frameworks/libintl.8.dylib:
@loader_path/../Frameworks/libintl.8.dylib (compatibility version 10.0.0, current version 10.5.0)
/Users/me/Library/Audio/Plug-Ins/Components/juicysfplugin.component/Contents/Frameworks/libpcre.1.dylib:
@loader_path/../Frameworks/libpcre.1.dylib (compatibility version 4.0.0, current version 4.9.0)

我以为我正确链接了它。我使用了完全相同的脚本(它是自动化的和参数化的)。 我究竟做错了什么?音频插件主机如何知道在 /usr/local 下查找依赖项?为什么我的图书馆链接被忽略了?

我已将二进制文件发布到: https://github.com/Birch-san/juicysfplugin/releases/tag/1.0.1

我的重新链接脚本在这里: https://github.com/Birch-san/juicysfplugin/blob/master/Builds/MacOSX/relink-build-for-distribution.sh
.app的主要区别如何和 .component使用的目标是:
  • .app是独立的
  • .component是一个音频单元插件,您可以将其加载到 DAW/音频插件主机中。

  • 那么,当父进程负责加载我们的可执行文件时,运行时依赖解析可能会有所不同?

    最佳答案

    好的,我 got it working .

    macOS 加载时链接记录在 man dyld .

    问题是我告诉我的二进制文件查找与 @executable_path 相关的库。 .

    这适用于 .app,因为 .app 的二进制文件 可执行文件。

    但是对于我的 .vst 和 .component 插件,二进制文件被加载到不同的可执行文件中:音频插件主机。

    因此,如果我们要查找与二进制文件 ( juicysfplugin.component/Contents/MacOS/juicysfplugin ) 相关的库,则 我们需要使用 @loader_path ,不是 @executable_path .

    现在,回到其他谜团……为什么加载时链接器忽略我的安装路径( @executable_path/../Frameworks/libfluidsynth.1.7.1.dylib ),而是在 /usr/local/lib/libfluidsynth.1.7.1.dylib 下寻找 find fluidsynth | ?

    这是因为DYLD_FALLBACK_LIBRARY_PATH !

    It is used as the default location for libraries not found in their install path. By default, it is set to $(HOME)/lib:/usr/local/lib:/lib:/usr/lib.



    我相信它 失败 在安装路径中找到库。然后它寻找那个叶子文件名—— libfluidsynth.1.7.1.dylib — 在几个目录下,包括 /usr/local/lib (成功了)。

    为什么我在 opensnoop 中没有看到失败的文件查找?可能它使用了与 open 不同的系统调用/ open_nocancel/ open_extended .例如,运行 stat在文件上没有显示在 opensnoop 中。

    加载时链接也可能由 dyld 完成过程。 SIP 将不允许将 DTrace 附加到此进程。

    关于macos - 我的目标与 brew 中的库动态链接。如何捆绑分发?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49223687/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com