“image not found” Error while using Custom FrameWo

2020-02-10 06:11发布

问题:

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:

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:

  • I followed this link: A Visual Guide to Creating an Embeddable Framework for Mac OSX

But I couldn't fix the issue, yet. Please help me, thanks in advance.

回答1:

Set framework installation directory to @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



回答2:

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

Follow the following steps,

  1. Go the Project Navigator
  2. Select the Targets, go the General tab
  3. Find Embedded Binaries drag the custom framework. Find the flow in the below-mentioned image
  4. Check if the Framework is added to the Linked Frameworks and Libraries (ref the image)
  5. NOTE: In my case it was added to Linked Frameworks and Libraries, go a head and remove it
  6. Last step, find the flag Always embed swift embedded librariesin "Build settings" and turn it to "YES" (ref the image)

I hope this helps.