在Mac OSX上使用Xcode4部署和分发OpenCV应用程序 [英] Deploy and distribute OpenCV applications with Xcode4 on Mac OSX

查看:94
本文介绍了在Mac OSX上使用Xcode4部署和分发OpenCV应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理OpenCV应用程序,我的问题是如何在非开发计算机(未安装OpenCV的计算机)上部署和分发该应用程序?

I'm working on an OpenCV application and my question is how can I deploy and distribute the application on non-development-machines, machines where OpenCV isn't installed?

我在带有OpenCV 2.2的Mac OS X Lion上使用Xcode4.

I'm using Xcode4 on Mac OS X Lion with OpenCV 2.2.

谢谢

推荐答案

这只是部分答案,因为我还没有弄清楚如何使用OpenCV库执行此操作. (已解决.请参见下面的更新..)但我已经使用其他库(

This is only a partial answer because I also haven't yet figured out how to do this with the OpenCV libraries. (Figured it out. See update below.) But I have done it with other libraries (SM2DGraphView).

需要发生三件事:

  1. 您需要将程序使用的OpenCV库复制到应用程序捆绑包中.为此(无论如何,在Xcode 3中),将复制文件"构建阶段添加到目标中.将库文件从Xcode的文件列表拖到构建阶段.双击复制文件"项,然后将目标设置为框架".

    请注意,您需要确保Xcode项目中包含的库是一个库文件,而不是到该库文件的符号链接.否则,只有符号链接将被复制到您的应用程序包中.

  1. You need to copy the OpenCV libraries that your program uses into the application bundle. To do that (in Xcode 3, anyway), add a Copy Files build phase to your target. Drag the library files from Xcode's file list onto the build phase. Double-click the Copy Files item and set the destination to Frameworks.

    Note that you need to make sure that the library you include in your Xcode project is a library file and not a symlink to a library file. Otherwise only the symlink will be copied to your application bundle.

OpenCV框架文件的安装路径需要设置为@executable_path/../Framework.如果框架是用Xcode构建的,则可以在项目设置中执行此操作.由于OpenCV不在Xcode中构建,因此您需要在install_name_tool命令行程序install_name_tool -id @executable_path/../Frameworks libopencv_imgproc.2.3.1.dylib之后执行此操作.您应该能够在目标的运行脚本"构建阶段中进行设置.

The install path of the OpenCV framework files needs to be set to @executable_path/../Framework. If the framework was being built in Xcode, you'd do this in the project settings. Since OpenCV is not being built in Xcode you need to do it after the fact with the install_name_tool command line program: install_name_tool -id @executable_path/../Frameworks libopencv_imgproc.2.3.1.dylib. You should be able to set this up in a Run Script build phase in your target.

可执行文件需要在捆绑软件的Frameworks目录中找到该库.这是我目前卡住的地方.

The executable needs to find the library in the bundle's Frameworks directory. This is where I'm currently stuck.

更新

我找到了正确的install_name_tool命令,以使程序可以查看库(以及用于查看其他库的库). 用于部署OS X程序的Qt页面上的信息是键.

I found the correct install_name_tool commands to get the program to see the libraries (and the libraries to see the other libraries). The information on the Qt page for deploying OS X programs was the key.

我在程序的Contents/MacOS目录中的可执行文件上运行otool -L,并看到了此[不相关的行已删除]:

I ran otool -L on the executable file in my program's Contents/MacOS directory and saw this [non-relevant lines removed]:

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)

因此,我使用了以下命令(位于Contents/MacOS目录中)使程序在正确的位置查找库:

So I used these commands (while in the Contents/MacOS directory) to get the program to 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 

然后我转到Contents/Frameworks目录,并使用以下命令告诉库它们的安装位置:

Then I changed 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

现在需要告知imgproc库,在哪里可以找到核心库,需要告诉highgui在哪里可以找到核心和imgproc:

Now the imgproc library needs to be told where to find the core library and highgui needs to be told where to find core 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 

我仍然遇到一个问题,其中highgui在/opt/local/bin中寻找很多库,但是我相当有信心问题的OpenCV部分已经解决.现在,我只需要将所有这些命令放入Xcode的构建阶段即可.

I'm still running into an issue where highgui is looking for a lot of libraries in /opt/local/bin but I'm fairly confident that the OpenCV part of the problem is solved. Now I just need to get all these commands into a build phase in Xcode.

这篇关于在Mac OSX上使用Xcode4部署和分发OpenCV应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆