问题
of course i did research before posting my question.
I looked at
How to "add existing frameworks" in Xcode 4?
Adding Framework in Xcode 4
Adding an OpenGL framework in Xcode 4
XCode 4 adding dylib
but whole thing is becoming wrong.
My goal: Add (CorePlot) framework to XCode Mac project (not an iPhone one)
My environment: OSX Lion 10.7, SDK Lion, XCode 4.1 (4B110)
My steps:
- Opened XCode, created new project
- Downloaded CorePlot into my libraries directory (like ~/Applications/LIBS)
- Opened project preferences, via (+) opened dialog to add framework
- Add existing framework (+ copy files to dest. group if needed)
- Selected directory was ~/Applications/LIBS/CorePlot/Binaries/MacOS/CorePlot.framework/
- DnD CorePlot to Frameworks Group
- Added CorePlot to
Build Phases > Link Binary with Libraries
and ran my project
what I got is this error message:
dyld: Library not loaded: @loader_path/../Frameworks/CorePlot.framework/Versions/A/CorePlot
Referenced from: /Users/username/Library/Developer/Xcode/DerivedData/metralight-hjuvuwlhgohrtdeepvcymnsaxomc/Build/Products/Debug/metralight.app/Contents/MacOS/metralight
Reason: image not found
And in fact, when I looked into given directory (app bundle) there was no directory Frameworks
and so the linking cannot be successful
I have searched one more, and found, that I can create Build Rule
and copy files into final binary bundle via some script, but is this only way how to do this?
Isn't there some option to just turn on/off copying linked frameworks to final bundle?
Note that CorePlot target '.framework' has Dynamic Library Install Name
set to @loader_path/../Frameworks/CorePlot.framework/Versions/A/CorePlot
, so it is looking in right place in final binary bundle
回答1:
After adding framework via "Add existing framework"
- Go to
Project Settings
>Build Phases
- In right bottom corner click
Add buid phase
>Copy Files
- Select Destination >
Frameworks
- Drag&Drop framework to files list
And that's it.
回答2:
Another important detail here - you must have the "Runtime search path" to be defined in the projects, it's empty by default.
Something like this:
LD_RUNPATH_SEARCH_PATHS = @loader_path/../Frameworks
来源:https://stackoverflow.com/questions/6972904/adding-a-framework-to-xcode-4