9

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

Public Header

  • I added the paths of Deployment and Linking like:

Paths

  • 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: Changed Path

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

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

Midhun MP
  • 103,496
  • 31
  • 153
  • 200
  • Does this help? http://stackoverflow.com/questions/9798623/xcode-dynamic-library-linking-how-to-properly-set-run-paths-search-paths-and – trojanfoe Nov 20 '13 at 10:11
  • @trojanfoe: No I tried that first, it not worked for me. That's why I asked this question :) – Midhun MP Nov 20 '13 at 10:14
  • But you didn't follow the accepted answer's advise of leaving *install name* to its default value. – trojanfoe Nov 20 '13 at 10:16
  • @trojanfoe: if we change the Installation directory and Run Path It'll automatically change the install name (Please check my image: The Install name is default, XCode shows changed one in bold and default value in normal font) – Midhun MP Nov 20 '13 at 10:19
  • Do you know where the app and framework are finally being written to? I would have thought an xcode workspace would be a better option for this kind of thing. – trojanfoe Nov 20 '13 at 10:22
  • @trojanfoe: Is any way to copy my framework to my binary's install folder (Xcode derived data folder) ? – Midhun MP Nov 20 '13 at 10:26
  • Is very simple. Only check this. http://stackoverflow.com/questions/24993752/os-x-framework-library-not-loaded-image-not-found#30979099 – jose920405 Apr 28 '16 at 14:29

2 Answers2

28

Set framework installation directory to @executable_path/../Frameworks

enter image description here

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

enter image description here

enter image description here

Parag Bafna
  • 22,812
  • 8
  • 71
  • 144
  • 4
    `Add Copy Files Build Phase` Menu is disabled in my XCode. – Midhun MP Nov 20 '13 at 12:02
  • @MidhunMP Did you select the correct target, and click on "Build Phases" tab ? – Emmanuel Nov 20 '13 at 12:17
  • 2
    @MidhunMP And the "Build Phases" tab is correctly selected ? Because "Add Build Phase" submenus are enabled only if you have selected the correct tab. – Emmanuel Nov 20 '13 at 13:44
  • @MidhunMP In Xcode 4, the option is in Editor->Add Build Phase. The Copy Files build phase then appears in the Project Navigator and you can add things to it by clicking the plus. – Parag Bafna Nov 20 '13 at 14:25
  • once in a while I forget this step. 1+ for this. – naz Mar 15 '15 at 11:16
3

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 imageenter image description here
  4. Check if the Framework is added to the Linked Frameworks and Libraries (ref the image)List item
  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)

enter image description here

I hope this helps.

aToz
  • 2,463
  • 1
  • 24
  • 34