This is only a partial answer, because I have not yet figured out how to do this with OpenCV libraries. ( Found this out. See update below. ). But I did it with other libraries ( SM2DGraphView ).
There are three things that must happen:
You need to copy the OpenCV libraries that your program uses in the application suite. To do this (in Xcode 3, anyway) add the build phase of the copy files to your target. Drag library files from the Xcode file list to the build phase. Double-click Copy Files and specify a destination in Structures.
Note that you need to make sure that the library that you included in the Xcode project is a library file, not a symbolic link to a library file. Otherwise, only the symbolic link will be copied to your application package.
The installation path of the OpenCV framework files must be installed in the @executable_path/../Framework . If the structure was built in Xcode, you must do this in the project settings. Since OpenCV is not built in Xcode, you need to do this after the fact using the install_name_tool command-line install_name_tool : install_name_tool -id @executable_path/../Frameworks libopencv_imgproc.2.3.1.dylib . You should be able to set this in the execution phase of the Script for your purpose.
The executable should find the library in the Frameworks directory. That's where I'm stuck right now.
Update
I found the correct install_name_tool commands so that the program can see the libraries (and libraries for viewing other libraries). The key was the Qt page for deploying OS X programs .
I ran otool -L in the executable file in the "Contents / MacOS" folder of the program and saw that these [inapplicable lines were deleted]:
lib/libopencv_core.2.3.dylib (compatibility version 2.3.0, current version 2.3.1) lib/libopencv_imgproc.2.3.dylib (compatibility version 2.3.0, current version 2.3.1) lib/libopencv_highgui.2.3.dylib (compatibility version 2.3.0, current version 2.3.1)
Therefore, I used these commands (in the Contents / MacOS directory) to make the program look in the right place for the libraries:
install_name_tool -change lib/libopencv_core.2.3.dylib @executable_path/../Frameworks/libopencv_core.2.3.1.dylib CocoaCVTest install_name_tool -change lib/libopencv_imgproc.2.3.dylib @executable_path/../Frameworks/libopencv_imgproc.2.3.1.dylib CocoaCVTest install_name_tool -change lib/libopencv_highgui.2.3.dylib @executable_path/../Frameworks/libopencv_highgui.2.3.1.dylib CocoaCVTest
Then I went to the Contents / Frameworks directory and used these commands to tell the libraries where they were installed:
install_name_tool -id @executable_path/../Frameworks/libopencv_core.2.3.1.dylib libopencv_core.2.3.1.dylib install_name_tool -id @executable_path/../Frameworks/libopencv_imgproc.2.3.1.dylib libopencv_imgproc.2.3.1.dylib install_name_tool -id @executable_path/../Frameworks/libopencv_highgui.2.3.1.dylib libopencv_highgui.2.3.1.dylib
Now the imgproc library needs to be told where to find the main library, and it is necessary to indicate where to find highgui, where to find the kernel and imgproc:
install_name_tool -change lib/libopencv_core.2.3.dylib @executable_path/../Frameworks/libopencv_core.2.3.1.dylib libopencv_imgproc.2.3.1.dylib install_name_tool -change lib/libopencv_core.2.3.dylib @executable_path/../Frameworks/libopencv_core.2.3.1.dylib libopencv_highgui.2.3.1.dylib install_name_tool -change lib/libopencv_imgproc.2.3.dylib @executable_path/../Frameworks/libopencv_imgproc.2.3.1.dylib libopencv_highgui.2.3.1.dylib
I still run into a problem when highgui searches a lot of libraries in / opt / local / bin, but I'm pretty sure that part of the OpenCV problem has been resolved. Now I just need to get all these commands in the build phase in Xcode.