MacOSX:如何将依赖项收集到本地包中?
我正在创建一个依赖于其他几个库的插件应用程序(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 install_name_tool 在 dylib 中使用相对路径。这样,您可以设置它们一次,然后将该目录安装在任何地方,而无需在安装时修改您的库。
您应该将所有 dylib 依赖项放入一个文件夹中,然后使用 install_name_tool 设置您依赖的其他 dylib 的相对位置。假设您的库 libmyfoo.dylib 依赖于 libbar.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:
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.为了完成克里斯托弗的回答,这里有一些有用资源的链接:
To complete Christopher's answer, here are some links to useful resources:
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.