Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a framework to XCode 4

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

like image 498
Marek Sebera Avatar asked Aug 07 '11 12:08

Marek Sebera


People also ask

How do I add a framework in Xcode?

To include a framework in your Xcode project, choose Project > Add to Project and select the framework directory. Alternatively, you can control-click your project group and choose Add Files > Existing Frameworks from the contextual menu.

How do I add a framework to a swift project?

In the app, select the project from the project navigator, select the Stocktance target, and scroll to Frameworks, Libraries, and Embedded Content. Click on the plus button, click Add Other… and select Add Files… Navigate to the SettingsKit folder and select it. We've added the framework to the project.

How do I open framework in Xcode?

Xcode has a tendancy to select the "openFrameworks" scheme instead of the one you actually want (which is your app). Select the dropdown in the top which says "openFrameworks" and set it to your app's name. If you find that you try to run your app and nothing happens, this is almost always the reason.


1 Answers

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.

like image 147
Marek Sebera Avatar answered Dec 02 '22 20:12

Marek Sebera