I created my own framework for one of my cocoa application. I added that framework to my project and called a method from that framework. When I tried to run my application it crashed:
我为我的一个可可应用程序创建了自己的框架。我将该框架添加到我的项目中并从该框架调用了一个方法。当我试图运行我的应用程序时,它崩溃了:
Crash Log:
dyld: Library not loaded: @rpath/MMP.framework/Versions/A/MMP
Referenced from: /Users/Midhun/Library/Developer/Xcode/DerivedData/MMPTest-ccvjtgedqkcftchapjehhwjbaqdq/Build/Products/Debug/MMPTest.app/Contents/MacOS/MMPTest
Reason: image not found
What I have done:
FrameWork:
- I added my header file in public section
我在公共部分添加了我的头文件
- I added the paths of Deployment and
Linking
like:
我添加了部署和链接的路径,如:
- I build the project and I got my framework ready (Pretty cool till here).
我构建了这个项目,并准备好了我的框架(直到这里很酷)。
Project:
- I added that framework to
FrameWorks
folder under my Project's root directory. - I added the framework under
Link Binary With Libraries
Section - I changed the path of Linking like:
我将该框架添加到Project的根目录下的FrameWorks文件夹中。
我在Link Binary With Libraries Section下添加了框架
我改变了Linking的路径:
Platform Details:
Xcode: 4.6.2
OS X : 10.8
What I have tried (After the crash)
我尝试了什么(崩溃后)
- When I get this issue, I checked with
otool
. It shows the paths like:
当我遇到这个问题时,我检查了otool。它显示了以下路径:
- I followed this link: A Visual Guide to Creating an Embeddable Framework for Mac OSX
我按照以下链接:为Mac OSX创建可嵌入框架的可视指南
But I couldn't fix the issue, yet. Please help me, thanks in advance.
但我无法解决这个问题。请帮助我,提前谢谢。
2 个解决方案
#1
25
Set framework installation directory to @executable_path/../Frameworks
将框架安装目录设置为@executable_path /../ Frameworks
Now add copy files in your build phase, set destination to Frameworks
. click on your target, then on Editor (menu bar) --> Add build phase --> Add Copy Files Build Phase
现在在构建阶段添加复制文件,将目标设置为Frameworks。单击目标,然后单击编辑器(菜单栏) - >添加构建阶段 - >添加复制文件构建阶段
#2
4
I've encountered the same issue and this is how I have solved it,
我遇到了同样的问题,这就是我解决它的方法,
For my case, custom Framework is in Swift and My project is in Objective c
对于我的情况,自定义框架在Swift中,我的项目在Objective c中
Follow the following steps,
请按照以下步骤操作
- Go the Project Navigator
- Select the Targets, go the General tab
- Find Embedded Binaries drag the custom framework. Find the flow in the below-mentioned image
- Check if the Framework is added to the Linked Frameworks and Libraries (ref the image)
- NOTE: In my case it was added to Linked Frameworks and Libraries, go a head and remove it
- Last step, find the flag Always embed swift embedded librariesin "Build settings" and turn it to "YES" (ref the image)
转到Project Navigator
选择目标,转到常规选项卡
查找嵌入式二进制文件拖动自定义框架。在下面提到的图像中找到流程
检查框架是否已添加到链接的框架和库(参考图像)
注意:在我的情况下,它被添加到链接框架和库,去头并删除它
最后一步,在“Build settings”中找到标记Always embed swift embedded libraries并将其转为“YES”(参考图像)
I hope this helps.
我希望这有帮助。
#1
25
Set framework installation directory to @executable_path/../Frameworks
将框架安装目录设置为@executable_path /../ Frameworks
Now add copy files in your build phase, set destination to Frameworks
. click on your target, then on Editor (menu bar) --> Add build phase --> Add Copy Files Build Phase
现在在构建阶段添加复制文件,将目标设置为Frameworks。单击目标,然后单击编辑器(菜单栏) - >添加构建阶段 - >添加复制文件构建阶段
#2
4
I've encountered the same issue and this is how I have solved it,
我遇到了同样的问题,这就是我解决它的方法,
For my case, custom Framework is in Swift and My project is in Objective c
对于我的情况,自定义框架在Swift中,我的项目在Objective c中
Follow the following steps,
请按照以下步骤操作
- Go the Project Navigator
- Select the Targets, go the General tab
- Find Embedded Binaries drag the custom framework. Find the flow in the below-mentioned image
- Check if the Framework is added to the Linked Frameworks and Libraries (ref the image)
- NOTE: In my case it was added to Linked Frameworks and Libraries, go a head and remove it
- Last step, find the flag Always embed swift embedded librariesin "Build settings" and turn it to "YES" (ref the image)
转到Project Navigator
选择目标,转到常规选项卡
查找嵌入式二进制文件拖动自定义框架。在下面提到的图像中找到流程
检查框架是否已添加到链接的框架和库(参考图像)
注意:在我的情况下,它被添加到链接框架和库,去头并删除它
最后一步,在“Build settings”中找到标记Always embed swift embedded libraries并将其转为“YES”(参考图像)
I hope this helps.
我希望这有帮助。