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...
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
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.
[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.
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
- Add a target to create a Cocoa Framework
- Within that targets 'Build Settings' configure the 'Installation Directory' to '@executable_path/../Frameworks'
- Build library, and access the .framework from the archive or products directory
Including The Framework
- Drag the created .framework file into the Xcode Project, be sure to tick 'Copy Files to Directory'
- In the containing applications target, add a new 'Copy File Build Phase'
- Set the 'Destination' to 'Frameworks'
- 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