Adding 3rd party framework into Xcode 4 project - objective-c

I'm trying to add a custom 3rd party framework into my Xcode 4 project for a program I'm trying to write for Mac OSX. The framework is libircclient found here: http://www.ulduzsoft.com/libircclient/
I have opened the Xcode project that was in the project cocoa directory and compiled it. Then I tried to drag the IRCClient.framework from the Products into my Xcode application but when I try to compile it there (my app currently is empty, its a brand new project), I get the following error:
dyld: Library not loaded: #executable_path/../Frameworks/IRCClient.framework/Versions/A/IRCClient
Referenced from: /Users/Ray/Library/Developer/Xcode/DerivedData/IRC-cokndyzxhwruxqevwngcznzijjcm/Build/Products/Debug/IRC.app/Contents/MacOS/IRC
Reason: image not found
Am I adding the framework correctly? I also tried right clicking on the IRCClient.framework and copying the whole directory to my application then tried to add it in the build phases in my app. I get the same error. What am I doing wrong?

It seems you forgot one single step:
the 'copy files' build phase must be added to your target (Add buildphase)
Set the destination to 'Frameworks' and drop your framework. (I was unable to select it after clicking the add button)

Related

How to link a stand-alone Swift OS X app to a private framework (also created in Swift)?

I get the following error when trying to embed a private framework into a Swift OS X app:
dyld: Library not loaded: #rpath/CustomCalcs.framework/Versions/A/CustomCalcs
Referenced from: /Users/sam/Library/Developer/Xcode/DerivedData/TestFramework-ckcpduuqyfclssceomyzqbxgbjdi/Build/Products/Debug/TestFramework.app/Contents/MacOS/TestFramework
Reason: image not found
I am trying to simulate the scenario where I am the receiver of a .framework file from a 3rd party and don't have access to the source code or Xcode project file (even though in my simple test of course I do)
Steps I have taken:
1. Add file to my target project making sure to copy it into the project
2. The Xcode syntax highlighting/completion then becomes aware of the classes within the framework - this is good
3. I add a "copy file" step in the Xcode "build phase". I have added it to "frameworks"
4. When examining the directory that the app runs from within DerivedData, I can find no framework directory and no .framework file
5. When I run the app the error above occurs
It would appear that I need to setup a step whereby the .framework file is copied into a deployment directory AND somehow the app knows to look in this location. How specifically do I go about doing this in Xcode?
I may be wrong but is seems like a case of "Linked Frameworks and Libraries" vs "Embedded Binaries".
Click on your project Workspace
Select your project Target
In the General tab, remove the Framework from "Linked Frameworks and Libraries"
Add it to "Embedded Binaries"
Build
It will be automatically added to the "Linked Frameworks and Libraries" also but you'll have it once instead of two times.

How to add framework to xcode

I am new to Xcode and want to add and use framework which I have taken from internet but
when I add it to my products folder by right clicking on products and using add new files it
runs fine and when i use my project's project.app file on my mac or on any other mac it
gives me dyld error that the bundle image not find. And when I use bundle image in my
framework folder its give me ld error that bundle not found help please.
ld: framework not found SMS-Bundled
Command /Developer/usr/bin/clang failed with exit code 1
*updated
when i add my framework to framework folder now its giving me error at run time...
dyld: Library not loaded: #executable_path/../Frameworks/SMS-Bundled.framework/Versions/A/SMS-Bundled
Referenced from: /Users/usman/Library/Developer/Xcode/DerivedData/Serial_Tools-detoutxzbnjrngcuulrbgcasxmjs/Build/Products/Debug/Serial Tools.app/Contents/MacOS/Serial Tools
Reason: image not found
(In Finder)
Go to the folder where your custom framework is. copy the framework. Now go to your project's folder. Create a new folder called Frameworks, paste the custom framework inside this folder.
(In Xcode)
Drag the custom folder FROM finder to the Frameworks folder on the project explorer (where all the rest of the frameworks are)
Now select your project, go to Build Settings, scroll down to "Framework Search Paths" field, double click the value to open it, press the + to add a new path, write ./Frameworks as the new path.
From now on if you want to add other private/custom frameworks all you have to do is copy them into the created frameworks folder, and simply drag and drop it into the xcode frameworks folder. (You must drag it from the project framework folder in finder to the framework folder in xcode).
PD: You don't necessarily have to name this folder frameworks, it can be whatever, just make sure to change the Framework Search Paths accordingly.
In your project build setting, under "framework search paths" mention the path of the framework.
This will resolve your issue.

Xcode 4 adding dylib

I am trying to create and then add the dylib to a project.
I created it by using the "Cocoa-Library" template and setting the type to "Dynamic" (not sure if it should be dynamic or static...). Then I created a simple obj-c class called Test and wrote a method in it that prints out something to console.
I compiled and used the generated .dylib file and put it in another project. Now whenever I try to use it, I get this message on runtime"
dyld: Library not loaded: /usr/local/lib/TESTLib.dylib
Referenced from: /Users/***/Library/Developer/Xcode/DerivedData/TestingDYLIB-axmoocnxbwznoyerfogosumqufxc/Build/Products/Debug/TestingDYLIB.app/Contents/MacOS/TestingDYLIB
Reason: image not found
I also created a Copy File phase and set the destination to "Frameworks". I still get the same error.
What am I doing wrong?
The issue is not where Xcode is looking for the library at compile time, which is what Simon Whitaker's answer addresses.
The issue is that the application which uses the dylib cannot find it at runtime. When an application is built that uses a dynamic library, it copies the install_name of the dylib into the output binary.
Creating a copy files phase and copying the dylib to the Frameworks subdirectory of the app's bundle is the right thing do do.
However, you need to do an additional step. You need to compile the dynamic library with an install_name appropriate for a bundle app. By default, a dynamic library is created with an install_name of /usr/local/lib. The app can't find your library there because it doesn't exist. Even if you put the library there, your users certainly won't have it, so that would be the wrong solution.
The right solution is bundling the library with the app. To set the install name for the dynamic library, go into the dynamic library project and set the "Dynamic Library Install Name" option to: #executable_path/../Frameworks/libmydynamiclibrary.dylib
Xcode is looking in /usr/local/lib/ for the library. If the library is in another location, add that location to your Library Search Paths:
Select project file in Xcode 4
Select the target, then click the Build Settings tab
Make sure All is selected in the filter bar (not Basic)
Scroll down to the Search Paths section and you'll find Library Search Paths in there

dyld not loaded problem xcode 4

I dragged skype fromwork into my frameworks folder and then imported <Skype/Skype.h>. When I run, it gives me this error:
dyld: Library not loaded: #executable_path/../Frameworks/Skype.framework/Versions/A/Skype
Referenced from: /Users/test/Library/Developer/Xcode/DerivedData/TEST-edktdfqvxhqmfpfqrdqrmjojnfly/Build/Products/Debug/TEST.app/Contents/MacOS/TEST
Reason: image not found
Try setting the "Library Search Path" build settings for your project.
In Xcode 4.x:
You need to drag the .framework from the Project navigator to the Copy Files build phase.
In Xcode 3.2.x:
Choose Project > New Build Phase > New Copy Files Build Phase
In the Destination drop down box select Frameworks
Close the Copy Files Phase Info window to return to the Xcode main window
In the Groups & Files pane expand Targets > YourApplicationExectuable, where you should now see a Copy Files entry
Still in Groups & Files pane drag your framework into the Copy Files entry
Recompile
If you don't do this, the framework will not be actually copied into your application bundle, so it will not be found when your app tries loading it into memory.
Just as a side note, I spent months trying to track down an answer to this problem, always seeing this answer but never being able to get it to work.
MY MISTAKE:
The "Copy Files" build phase is not shown by default. I was seeing the "Copy Bundle Resources" phase and wrongly assuming that was where I needed to list the framework.
At the bottom of the Build Phases pane click on Add Build Phase. "Copy Files" is listed there.
Doesn't work for me. I had to make a link to the framework in the ~/Library/Developer/..../Debug/../Frameworks for it to work.

Can't run my app; “image not found” referring to bundled framework

I'm trying to include the Sparkle framework in my application. I don't really understand the specific steps necessary, and am now getting this error message:
Dyld Error Message:
Library not loaded: #loader_path/../Frameworks/Sparkle.framework/Versions/A/Sparkle
Referenced from: <..>/build/Debug/CoRay.app/Contents/MacOS/CoRay
Reason: image not found
So my question is two part:
1. How do I fix my problem?
2. What is the correct path for including a framework into a Cocoa/Obj-C application?
The error is saying that it cannot find a copy of the sparkle framework inside of your app bundle.
You need to add a new Copy Files build phase to your target. Set it to "Frameworks" to copy frameworks and drag a copy of Sparkle.framework from your Xcode project into the new Copy Files build phase that you have just created.
After adding Sparkle.framework in "Copy Files" phase, you have to remove it from "Link Binary With Libraries".
Cheers.