MacOSX:如何将依赖项收集到本地包中?

发布于 2024-08-18 12:17:19 字数 439 浏览 11 评论 0原文

我正在创建一个依赖于其他几个库的插件应用程序(dylib)。这些其他库安装在我的系统上,但不保证安装在任何用户的系统上。所以我需要找到一种方法将依赖项与我的应用程序捆绑在一起。

我发现我可以使用 otool 列出或更改其他 dylib 的路径。这将允许创建一个文件夹来捆绑我的插件应用程序和所有需要的依赖项。

然而,手动执行此操作似乎是一项耗时且愚蠢的任务。是否有实用程序可以使其自动化?

或者也许我做错了,并且有一个更好、更明显的方法来解决这个问题?

编辑 我创建了一个脚本,它可以自动执行大多数操作任务。

I am creating a plugin application (dylib) that depends on several other libraries. These other libraries are installed on my system, but are not guaranteed to be installed on any user's system. So I need to find a way bundle the dependencies along with my application.

I found that I can use otool to list or change the paths to other dylibs. This would allow to create a folder that bundles my plugin application and all needed dependencies.

However, doing this manually seems like a time-consuming and dumb task. Are there utilities available to automate it?

Or perhaps I'm doing it wrong and there is a better and more obvious approach for this problem?

Edit
I created a script that automates most the task.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

转瞬即逝 2024-08-25 12:17:19

使用 install_name_tool 在 dylib 中使用相对路径。这样,您可以设置它们一次,然后将该目录安装在任何地方,而无需在安装时修改您的库。

您应该将所有 dylib 依赖项放入一个文件夹中,然后使用 install_name_tool 设置您依赖的其他 dylib 的相对位置。假设您的库 libmyfoo.dylib 依赖于 libbar.dylib:

install_name_tool -change "/Whatever/full/path/libbar.dylib" "@loader_path/libbar.dylib" libmyfoo.dylib

这样,您的库将始终在 libmyfoo.dylib 所在的同一目录中查找 libbar.dylib。

您可能还需要在其他一些 dylib 上运行 install_name_tool (如果它们相互依赖)。

请注意,install_name_tool 指出“要使此工具在安装名称或 rpath 较大时工作,应使用 ld(1) -headerpad_max_install_names 选项构建二进制文件。”,因此请务必包含 -headerpad_max_install_names构建库时的命令行选项。

@loader_path 与用于加载 dylib 的二进制文件相关,在本例中为 libmyfoo.dylib。如果您想查找与启动库加载序列的可执行文件相关的库,请使用@executable_path。

Use relative paths in your dylib using install_name_tool. That way you can set them once, and install that directory anywhere without needing to modify your libraries at install time.

You should place all of your dylib dependencies into one folder, then use install_name_tool to set the relative location of the other dylibs you depend on. Suppose your library libmyfoo.dylib depends on libbar.dylib:

install_name_tool -change "/Whatever/full/path/libbar.dylib" "@loader_path/libbar.dylib" libmyfoo.dylib

This way, your library will always look for libbar.dylib in the same directory where libmyfoo.dylib is located.

You might also need to run install_name_tool on some of the other dylibs, if they depend on one another.

Beware, the documentation for install_name_tool points out that "For this tool to work when the install names or rpaths are larger the binary should be built with the ld(1) -headerpad_max_install_names option.", so be sure to include the -headerpad_max_install_names command line option when building your library.

@loader_path is relative to the binary used to load the dylib, in this case your libmyfoo.dylib. Use @executable_path if you want to find the libraries relative to executable that started the library loading sequence.

寒江雪… 2024-08-25 12:17:19

为了完成克里斯托弗的回答,这里有一些有用资源的链接:

To complete Christopher's answer, here are some links to useful resources:

两仪 2024-08-25 12:17:19

Macdylibbundler 是一个方便的小工具,它完全可以满足要求。在分发 OSX 二进制文件时,它确实救了我的命。

Macdylibbundler is a handy little tool which does exactly what is asked for. It certainly saved my life when distributing binaries for OSX.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文