I am an XCode novice. I am trying to follow these instructions. 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. (Here’s a screenshot of the project as requested in comments.)
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/OpenCV <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 by dragging the icon from the Project Navigator on the left side of Xcode window. Note that Xcode won't allow you to add a folder to the Copy Files phase by using the '+' button so in order to copy the framework you'll have to drag&drop it.
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 https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPFrameworks/Tasks/CreatingFrameworks.html
Regards
Using Xcode 5, you can facilitate this using the Build Phases
panel of your application target.
The default appearance of this panel is
By pressing the "+" button underneath Copy Files, you can add your framework as a file that will be copied into Frameworks in your app bundle.
Now, when you build, your Framework(s) will be copied into your bundle.
精彩评论