我使用 xcode 4 构建一个带有私有 dylib/框架的可可应用程序.
I use xcode 4 to build a cocoa application with a private dylib/framework.
在我的开发Mac中,我把dylib放在/usr/local/lib目录下,然后拖到项目中.
In my development Mac, I put the dylib in the /usr/local/lib directory, and drag it into the project.
该应用程序已编译并在我的计算机上完美运行.
The app is compiled and runs perfect on my computer.
为了将此应用分发到另一台 Mac,我创建了一个复制文件构建阶段,并说将那个 dylib 复制到 Frameworks 目录".
To distribute this app to the other Mac, I create a copy Files building phase, and say "copy that dylib to Frameworks directory".
应用构建成功,我确实看到dylib被复制到了app bundle的Frameworks目录中.
The application is built successfully, and I indeed see the dylib is copied to the Frameworks directory in the app bundle.
问题是当我在另一个没有安装这个 dylib 的普通 Mac 上运行这个应用程序时.我收到一条错误消息:
The problem is when I run this app in another regular Mac, which does not have this dylib installed. I get an error saying:
dyld: Library not loaded: /usr/local/lib/mylib.dylib
问题在于您将框架复制到应用程序包中,因此它可以在以下位置使用:
The issue comes from the fact that you copy the framework into the app bundle, so it is available at a location like:
<you_app_path>/Contents/Frameworks
但您尝试从 /usr/local/lib
加载它,但它在您的部署机器上不可用.来自 Apple 框架编程指南:
but you try to load it from /usr/local/lib
where it is not available on you deployment machine. From Apple Framework Programming Guide:
要将框架嵌入到应用程序中,您必须执行几个步骤:
To embed a framework in an application, there are several steps you must take:
您必须配置应用程序目标的构建阶段,以将框架放置在正确的位置.
You must configure the build phases of your application target to put the framework in the correct location.
您必须配置框架目标的安装目录,该目录告诉框架它将位于何处.
You must configure the framework target’s installation directory, which tells the framework where it will live.
您必须配置应用程序目标,以便它引用其安装目录中的框架.
You must configure the application target so that it references the framework in its installation directory.
现在,你说构建阶段没问题;我还假设您正确发送了应用程序目标构建设置.剩下的就是配置框架目标的安装目录了.
Now, you say that the build phase is ok; I assume also that you sent the application target build setting correctly. What is left is configuring the framework target’s installation directory.
如果您没有自己构建框架,您应该能够通过更改框架安装路径来解决此问题,以便将其定义为相对于加载器(您的应用程序),例如:@loader_path/../Frameworks/
(或 @executable_path/../Frameworks
).您可以通过 install_name_tool.
If you did not build the framework yourself, you should be able to fix this by changing the framework install path so that it is defined relative to the loader (your app), to something like: @loader_path/../Frameworks/
(or @executable_path/../Frameworks
). You can do that by means of install_name_tool.
如果您自己编译私有框架,您可以在 Xcode 构建设置中定义其安装位置.
If you are compiling on your own the private framework, you can define its install location in Xcode build settings.
这篇关于使用私有 dylib/framework 构建 Cocoa 应用程序包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!