我写了一个关键取决于OpenCV的程序。我已经从最新的稳定版本编译了OpenCV,现在想分发这个程序,以确保人们不需要自己编译OpenCV。程序本身使用g ++编译。
我尝试了很多方法来解决这个问题:
编译OpenCV作为静态库工作,但我不能静态地将我的程序链接到这些库,因为OS X中的某些库不能静态链接;我在此处找到了此信息:Mixed static and dynamic link on Mac OS
我试图转移到XCode,在那里我将它用作命令行项目。我将搜索路径以及安装位置设置为@rpath,并添加了构建阶段以将文件复制到可执行文件。我用otool验证了编译后的文件是否具有正确的链接,但是在一台干净的机器(没有OpenCV库的机器)上仍然出现故障,并且“找不到库@rpath / libopencv ...”错误。 (是的,所有的mac都使用Lion,所以@rpath应该可以工作)。这个答案在这里找到:Xcode keeps searching dylib at wrong path
我从runnig otool -L获得的编译文件和库的结果是
@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)
那么......我做错了什么?我如何将这些库与我的程序一起分发?
答案 0 :(得分:2)
您应该使用框架(SO question on frameworks)。将您的应用程序使用的所有内容合并到一个文件夹中,然后链接到XCode项目中的框架。
答案 1 :(得分:1)
我最近必须这样做才能在applet中运行JavaCV。这个命令应该完成工作:
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
并使用这些和所需的“-rpath”选项重新链接您的软件。