Xcode、构建和动态库 [英] Xcode, building and dylibs

查看:32
本文介绍了Xcode、构建和动态库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看了一些相关问题,但似乎无法为自己找到解决方案.

I've looked at a few related questions and cannot seem to find a solution for myself.

基本上我在我的 Xcode 项目中使用 libmp3lame.dylib.lame 的安装过程生成了 .dylib 并将其放置在 usr/local/lib 中,为了让 Xcode 构建和运行项目,我更改了库搜索路径以包含上述文件夹.这工作正常.

Basically I'm using the libmp3lame.dylib in my Xcode project. The install process for lame produced the .dylib and placed it in usr/local/lib and to get Xcode to build and run the project I changed the Library Search Paths to include the above folder. This works fine.

现在开始制作发行版,我想将 .dylib 包含在包中,这样用户就不必忍受安装阶段或任何类似的事情.我创建了目标的复制文件阶段,这将 .dylib 转储到包内容中的 Frameworks 文件夹中.但是,在二进制文件上运行 otool 表明,编译器没有在包中使用 .dylib,而是将其链接到 usr/local/lib 版本(即使我删除了该版本).

Now it's come to producing a release version and I want to include the .dylib in the bundle so that the user doesn't have to put up with an install phase or anything similar. I created a copy files phase of the target and this dumps the .dylib into the Frameworks folder in the contents of the bundle. However, running otool on the binary shows that instead of using the .dylib inside the bundle, the compiler has linked it to the usr/local/lib version (even if I delete that version).

查看 otool 输出中的其他结果,我在包内链接了其他框架,而不是 .dylib.在 Xcode 中查看这些框架和 .dylib 的属性时,除了文件类型之外,我看不出任何区别.

Looking at the other results in the otool output I have other frameworks being linked to inside the bundle, just not the .dylib. Looking at the properties for both these frameworks and the .dylib in Xcode I can't see any differences other than file type.

我的搜索表明我需要使用 rpath 或类似的,但我不知道在 Xcode 中的何处应用它.

My searching suggests I need to use rpath or similar, but I've no clue where to apply this in Xcode.

推荐答案

我对这个问题的解决方法是在终端中执行以下操作(我已经使用 Automator 将其自动化):

My workaround for this issue was to do the following in terminal (I've used Automator to, well, automate this):

install_name_tool -id @executable_path/../Frameworks/libmp3lame.0.0.0.dylib ~/path/to/lib/in/app/libmp3lame.0.0.0.dylib

install_name_tool -change /usr/local/lib/libmp3lame.0.dylib @executable_path/../Frameworks/libmp3lame.0.0.0.dylib ~/path/to/app/Contents/MacOS/AppName

基本上将库的路径从 usr 本地库中的路径交换到包中包含的路径.

Basically swapping the path to the library from the one in the usr local lib to the one included in the bundle.

这篇关于Xcode、构建和动态库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆