views:

1099

answers:

2

I am an XCode novice. I am trying to follow these instructions:

http://wiki.remobjects.com/wiki/Linking%5FCustom%5FFrameworks%5Ffrom%5Fyour%5FXcode%5FProjects

Clearly I am missing something because while I can see that the framework I want has been copied into the app bundle, I can't reference it.

When I start the application from a machine other than mine (or if I remove OpenCV from /Library/Frameworks/ ) I get the following error:

Dyld Error Message: Library not loaded: /Users/david/Library/Frameworks/OpenCV.framework/Versions/A/OpenCV Referenced from: /Users/g/Demo/Slates/ClipSplitter/build/Release/ClipSplitter.app/Contents/MacOS/ClipSplitter Reason: image not found

There is no user "david" on my system if that makes any difference.

Also this is a prebuilt OpenCV downloaded from the internet.

EDIT: Screenshot of project as requested in comments:

+2  A: 

When the OpenCV.framework has been build it has been configured to use an install path of /Users/david/Library/Frameworks/.

Since you want to use the library as a private framework (installed in the application wrapper at ClipSplitter.app/Contents/Frameworks/OpenCV.framework) you have to change its install path. This can be done easily using the terminal as follows:

$ install_name_tool -id @executable_path/../Frameworks/OpenCV.framework <your_path>/OpenCV.framework/OpenCV

Of course you have to adjust the path of the last argument.

Now, when linking your application, your modified framework tells the linker that dyld has to search for the OpenCV.framework in the app wrapper of your application (in the ClipSplitter.app/Contents/Frameworks directory).

Now you have to copy the OpenCV.framework to your application wrapper. You can do this as part of your build process by adding a copy files build phase: Right-click on your target, select Add->New Build Phase->New Copy Files Build Phase. Select "Frameworks" from the "Destination" pop up and close the dialog. Your target will now contain a new phase to which you can add the OpenCV.framework.

Nikolai Ruhe
This was almost completely right. The command I actually had to run was: $ install_name_tool -id @executable_path/../Frameworks/OpenCV.framework/OpenCV <your_path>/OpenCV.framework/OpenCV but this was more than enough to get me there. Thanks!!!!
Gareth Simpson
Oops, right. That happens if you don't try what you're typing. Sorry for the confusion.
Nikolai Ruhe
A: 

You need to set the build setting "Installation directory" to @executable_path/../Frameworks

See the chapter about Embedding a Private Framework in Your Application Bundle in http://developer.apple.com/mac/library/documentation/MacOSX/Conceptual/BPFrameworks/Tasks/CreatingFrameworks.html

Regards

Colin Delacroix
You should at least mention that this setting has to by applied when building the framework, not the application that links the framework.
Nikolai Ruhe
Yeah, I'm sure this is good advice except I didn't build the OpenCV framework, I downloaded it prebuilt.
Gareth Simpson
I missed the last sentence, Nikolai's answer is more appropriate in that case. I'm not sure why you would rather spend time fixing broken prebuilt open-source libraries rather than building them properly, though.
Colin Delacroix
I thought it would be quicker. And it was up until the point where I tried to run it on a different machine :)
Gareth Simpson