OpenCV for OSX

Thursday, June 22, 2017
By keiji
I had really hard time building OpenCV for OSX. So here is a memo.
Below, I used XCode 8.3.3, and OpenCV 3.2.0. (As of 2017-6-22)

1. Download the OpenCV source Open CV Download site, and unzip it somewhere.
For example:
Unzip it in /SDK/opencv3/opencv-3.2.0/

2. Download CMake if you don't have it.

3. Create a folder for the build.
e.g. /SDK/opencv3/build

4. Use CMake, point to the root folder of the OpenCV folder.
"Where is the source code": /SDK/opencv3/opencv-3.2.0/
"Where to build the binaries": /SDK/opencv3/build

5. Generate the xcode project.

6. Open the xcode project (It should be in /SDK/opencv3/build), and build it.
Build both "command-B" and "Archive".
This way, it generates dylib in the folder: /SDK/opencv3/build/lib
The dylib in this folder is a link, so go to the original file folder by right click and select "Show Original"

These dylib has the ID with rpath, so it's safe to be embedded in the App package.
otool -L libopencv_imgproc.3.2.0.dylib
@rpath/libopencv_imgproc.3.2.dylib (compatibility version 3.2.0, current version 3.2.0)
@rpath/libopencv_core.3.2.dylib (compatibility version 3.2.0, current version 3.2.0)
/System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate (compatibility version 1.0.0, current version 4.0.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 307.5.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.50.2)

However, the ID is different:
e.g. libopencv_imgproc.3.2.0.dylib pointing to @rpath/libopencv_imgproc.3.2.dylib

So, to be able to be included it in App Packege, rename the dylib:
libopencv_imgproc.3.2.0.dylib ==> libopencv_imgproc.3.2.dylib

Now, you can copy those dylib into your project, and link.
Make sure to use "Embed Frameworks" to included these dylibs.



Reply to

(Max 1000 chars)
Confirmation Key:
Please enter the value displayed in the image.
Send Send