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

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

问题描述

谁能为我提供一些详细的指南,如何在 OS X Lion 上使用 Xcode 编译 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 在 OS X Lion (10.7.2) 和 Xcode 4.2.1 下启动和运行 OpenCV 2.3.1

EDIT 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).

EDIT 15/08/2012: 使用 Mountain Lion 和当前版本的 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.

EDIT 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.) 确保为我们准备好 brew

2.) Make sure brew is ready to us

brew doctor && brew update 

3.) 安装 OpenCV(截至 17/20/2014 v2.4.9)

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

brew install opencv

4.) 启动 Xcode(截至 17/20/2014 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"添加到Build Settings"下的Header Search Paths"(仍然选择目标)

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 的当前版本.不要忘记将/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.) 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"

就是这样!希望它有帮助:)

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

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