OS X Framework Library not loaded: 'Image not found'

I am trying to create a basic OS X Framework, right now I just have a test framework created: TestMacFramework.framework and I'm trying to import it into a brand new OS X Application project.

I have built the .framework file and imported it into the new project, The framework appears to link okay, and I can reference the public header file I added to the framework build phases section.

However, when I try to run the container Application I get the following Error:

dyld: Library not loaded: /Library/Frameworks/TestMacFramework.framework/Versions/A/TestMacFramework
  Referenced from: /Users/samharman/Library/Developer/Xcode/DerivedData/TestMacContainer-dzabuelobzfknafuhmgooqhqrgzl/Build/Products/Debug/TestMacContainer.app/Contents/MacOS/TestMacContainer
  Reason: image not found

After a bit of googling I realised I needed to add a Copy Files section to my container application build phases, so I have done this and set it up like so...

enter image description here

However, I am still getting the runtime error. I'm obviously doing something wrong here, but the Apple developer library resource for this references Xcode 2, so isn't very helpful!

What have I missed?

UPDATE:

I can see in the build log that my TestMacFramework.framework is being copied into the .app contents/frameworks directory, but it isn't being installed to the Library/Frameworks directory on the HD

enter image description here

UPDATE 2:

The build links correctly if I manually copy the TestMacFramework.framework into the Library/Frameworks directory


Solution 1:

[Xcode 11+]

The only thing to do is to add the framework to the General->Frameworks, Libraries And Embedded Content section in the General tab of your app target.

Make sure you select the 'Embed & Sign' option.

enter image description here

[Xcode v6 -> Xcode v10]

The only thing to do is to add the framework to the Embedded binaries section in the General tab of your app target.

Screenshot from Xcode

Solution 2:

So I managed to get it working, it's quite simple when you have the right instructions. What I was looking for was a 'private' framework which lives in the App bundle rather than being written to the system library folder.

Building The Framework

  1. Add a target to create a Cocoa Framework
  2. Within that targets 'Build Settings' configure the 'Installation Directory' to '@executable_path/../Frameworks'
  3. Build library, and access the .framework from the archive or products directory

Including The Framework

  1. Drag the created .framework file into the Xcode Project, be sure to tick 'Copy Files to Directory'
  2. In the containing applications target, add a new 'Copy File Build Phase'
  3. Set the 'Destination' to 'Frameworks'
  4. Drag in the created .framework

Solution 3:

It was quite simple for me, i just added my framework to my embedded binaries under app targets