Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
481 views
in Technique[技术] by (71.8m points)

macos - Compile OpenCV (2.3.1+) for OS X Lion / Mountain Lion with Xcode

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

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.

Thanks in advance, Dom

SOLUTION in my answer post.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Detailed guide how to get OpenCV 2.3.1 up and running under OS X Lion (10.7.2) with Xcode 4.2.1 using MacPorts

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: 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: Over the last year I abandoned MacPorts and started using brew, which works better for my purposes.

Brew guide

1.) Get the current Version of Brew here.

2.) Make sure brew is ready to us

brew doctor && brew update 

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

brew install opencv

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

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

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

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

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

MacPorts guide (maybe outdated)

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.) Keep your MacPorts up-2-date:

sudo port -v selfupdate

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

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

4.) Fire up Xcode and create your project

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

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

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

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

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 :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...