Reputation: 842
I have written a program that crucially depends on OpenCV. I have compiled OpenCV from the latest stable version and would now like to distribute this program, to ensure that people do not need to compile OpenCV by themselves. The program itself is compiled using g++.
I tried a number of things to resolve this issue:
compiling OpenCV as static libraries works, but I cannot statically link my program to these libraries as some libraries in OS X cannot be statically linked; I found this information here: Mixed static and dynamic link on Mac OS
I tried to move to XCode, where I used it as a command line project. I set the search path as well as the installation location to @rpath and added a build phase to copy the files to Executables. I verified with otool whether the compiled file has the correct links but it still fails on a clean machine (one that does not have the OpenCV libraries) with a "Library not found @rpath/libopencv..." error. (Yes, all macs use Lion, so @rpath should work). This answer was found here: Xcode keeps searching dylib at wrong path
the result I get from runnig otool -L on both the compiled file and the library is
@rpath/libopencv_core.2.4.dylib (compatibility version 2.4.0, current version 2.4.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 52.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
So ... what am I doing wrong? And how can I distribute these libraries together with my program?
Upvotes: 1
Views: 1925
Reputation: 4994
I've had to do that recently to run JavaCV in an applet. This command should get the job done:
BADPATH=/opt/local/lib # in the case of MacPorts, change as necessary
for f in libopencv*2.4.dylib; do install_name_tool $f -id @rpath/$f \
-add_rpath /opt/local/lib/ -add_rpath /usr/local/lib/ -add_rpath @loader_path/. \
-change $BADPATH/libopencv_core.2.4.dylib @rpath/libopencv_core.2.4.dylib \
-change $BADPATH/libopencv_calib3d.2.4.dylib @rpath/libopencv_calib3d.2.4.dylib \
-change $BADPATH/libopencv_features2d.2.4.dylib @rpath/libopencv_features2d.2.4.dylib \
-change $BADPATH/libopencv_flann.2.4.dylib @rpath/libopencv_flann.2.4.dylib \
-change $BADPATH/libopencv_gpu.2.4.dylib @rpath/libopencv_gpu.2.4.dylib \
-change $BADPATH/libopencv_highgui.2.4.dylib @rpath/libopencv_highgui.2.4.dylib \
-change $BADPATH/libopencv_imgproc.2.4.dylib @rpath/libopencv_imgproc.2.4.dylib \
-change $BADPATH/libopencv_legacy.2.4.dylib @rpath/libopencv_legacy.2.4.dylib \
-change $BADPATH/libopencv_ml.2.4.dylib @rpath/libopencv_ml.2.4.dylib \
-change $BADPATH/libopencv_nonfree.2.4.dylib @rpath/libopencv_nonfree.2.4.dylib \
-change $BADPATH/libopencv_objdetect.2.4.dylib @rpath/libopencv_objdetect.2.4.dylib \
-change $BADPATH/libopencv_photo.2.4.dylib @rpath/libopencv_photo.2.4.dylib \
-change $BADPATH/libopencv_video.2.4.dylib @rpath/libopencv_video.2.4.dylib; done
And relink your software with those and the desired "-rpath" option.
Upvotes: 1
Reputation: 14467
You should use Frameworks (SO question on frameworks). Combine all the stuff your app uses in one folder and then link to the framework in your XCode project.
Upvotes: 2