使用Xcode编译OS X Lion/Mountain Lion的OpenCV(2.3.1+) [英] Compile OpenCV (2.3.1+) for OS X Lion / Mountain Lion with Xcode

查看:72
本文介绍了使用Xcode编译OS X Lion/Mountain Lion的OpenCV(2.3.1+)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以给我一些详细的指南,说明如何使用Xcode在OS X Lion上编译OpenCV 2.3.1吗?

Can anyone provide me some detailed guide how to compile OpenCV 2.3.1 on OS X Lion with Xcode?

对此我感到非常生气……我得到了源代码,使用cmake创建了Xcode模板并尝试构建它,但是它失败并出现了大约200个错误.

I'm getting mad about this … I got the source, used cmake to create the Xcode template and tried to build it, but it fails with about 200 errors.

预先感谢, Dom

解决方案.

推荐答案

详细指南,介绍如何使用MacPorts在Xcode 4.2.1和OS X Lion(10.7.2)上启动并运行OpenCV 2.3.1 strong>

编辑08/06/2012: 这也适用于OpenCV 2.4.1.只需确保您已获得最新版本的Xcode并安装了命令行工具"(Xcode->首选项->下载->命令行工具).

EDIT 08/06/2012: This is also working for OpenCV 2.4.1. Just make sure you got the latest version of Xcode and installed the "Command Line Tools" (Xcode -> Preferences -> Downloads -> Command Line Tools).

编辑15/08/2012: 使用Mountain Lion ans和Xcode&的最新版本进行了测试. OpenCV…它正在工作:)而且您不必使用LLVM编译器.

EDIT 15/08/2012: Tested everything with Mountain Lion ans the current versions of Xcode & OpenCV … it's working :) And you don't have to use the LLVM compiler.

编辑16/10/204: .在过去的一年中,我放弃了MacPorts,开始使用brew,这对于我的目的来说效果更好.

EDIT 16/10/204: Over the last year I abandoned MacPorts and started using brew, which works better for my purposes.

1.)在此处.获取当前的Brew版本.

1.) Get the current Version of Brew here.

2.)确保准备好冲泡

2.) Make sure brew is ready to us

brew doctor && brew update 

3.)安装OpenCV(自2014年10月20日v2.4.9起)

3.) Install OpenCV (as of 17/20/2014 v2.4.9)

brew install opencv

4.)启动Xcode(自2014年20月20日v6.0.1起)并打开/创建您的项目

4.) Fire up Xcode (as of 17/20/2014 v6.0.1) and open/create your project

5.)选择目标,转到常规",然后单击链接的框架和库"中的"+"按钮.

5.) Select your target, go to "General" and hit the "+"-Button in the "Linked Frameworks and Libraries"

5.1.)单击添加其他",单击"/",转到"/usr/local/lib",然后添加所需的任何libopencv _ **.dylib

5.1.) Click "Add Other", hit "/", go to "/usr/local/lib" and add any libopencv_**.dylib you need

6.)现在,将"/usr/local/include"添加到构建设置"下的标题搜索路径"(仍选择目标)

6.) Now add "/usr/local/include" to your "Header Search Paths" under "Build Settings" (target still selected)

7.)最后确保您的.mm文件中包含OpenCV.

7.) Finally make sure include OpenCV in your .mm files.

1.)在此处获取当前版本的MacPorts.不要忘记在您的环境PATH中添加"/opt/local/(s)bin"

1.) Get the current Version of MacPorts here. Don't forget to add "/opt/local/(s)bin" to your environment PATH

export PATH=/opt/local/bin:/opt/local/sbin:$PATH

2.)保持MacPorts处于更新状态2:

2.) Keep your MacPorts up-2-date:

sudo port -v selfupdate

3.)安装OpenCV 2.3.1(使用llvm-gcc构建)

3.) Install OpenCV 2.3.1 (building with llvm-gcc)

sudo port install opencv configure.compiler=llvm-gcc-4.2

4.)启动Xcode并创建您的项目

4.) Fire up Xcode and create your project

5.)选择目标,转到摘要",然后单击链接的框架和库"中的"+"按钮

5.) Select your target, go to "Summary" and hit the "+"-Button in the "Linked Frameworks and Libraries"

5.1.)单击添加其他",单击"/",然后转到"/opt/local/lib"

5.1.) Click "Add Other", hit "/" and go to "/opt/local/lib"

5.2.)添加所需的任何libopencv _ **.dylib

5.2.) Add any libopencv_**.dylib you need

6.)现在,将"/opt/local/include/"添加到构建设置"下的标题搜索路径"中(仍然选择目标)

6.) Now add "/opt/local/include/" to your "Header Search Paths" under "Build Settings" (target still selected)

7.)最后,请确保在.pch文件的开头包含以下几行:

7.) Finally make sure to have the following lines at the beginning of your .pch file:

#ifdef __cplusplus
  #import "opencv2/opencv.hpp"
#endif

否则,您会得到一些讨厌的错误,如下所示:

Otherwise you'll get some nasty erros like this:

"Non-const static data member must be initialized out of line"
"Statement expression not allowed at file scope"

就是这样!希望对您有所帮助:)

That's it! Hope it helps :)

这篇关于使用Xcode编译OS X Lion/Mountain Lion的OpenCV(2.3.1+)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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