# Build opencv.framework for Swift on Mac OS

[Mac OS 10.13.3, Xcode9.2/Swift4, updated Homebrew, multiple OpenCV installations]

I'm in need of a opencv.framework for a Swift/OpenCV project I'm working on in Xcode. I found some instructions on how this may be done at Installation in iOS, and, after cloning opencv, was pleased to find the platforms/osx folder. Using the commend python platforms/osx/build_framework.py macos, I was optimistic that I would get something along the lines of what I needed. However, the build failed and thus I'm here asking this question.

There are two parts to my question; how to build the desired framework version and how to fix the build errors I encountered:

(1) Since platforms/osx/build_framework.py wasn't introduced until late 2015 (I think), I'm wondering how I might be able to build a framework around OpenCV 2.4.13.2? (platforms/osx did not exist when I checked out the 2.4.13.2 tag.)
(1a) If (1) can't be done, I also have OpenCV versions 3.3.1_1 and 3.4.0_1 installed via Homebrew in the Cellar. (In addition, I have the 2.4.9 LinkedKeg version as well.) I'm not at liberty to simply use the latest version of OpenCV.

(2) I've included the build output of the python command below. From its output, I'm not sure why ffmpeg was not found because I have it installed (v3.4 and v3.4.1) via Homebrew and, I have pkg-config (0.29.2) installed in /usr/local/bin, (I actually have three versions; v0.29.1, v0.29.1_1, and v0.29.2 installed via Homebrew). This may not be a critical error, as it didn't stop the build process, so I'm content to not worry about it too much at this point.

(3) However, the /usr/local/lib/cmake/vtk-6.1/VTKTargets.cmake error is what I'm most concerned about. As with my other Homebrew packages, I have multiple versions of VTK installed; two in the Homebrew Cellar (v8.1.0 and v8.0.1_1) as well as the desired version (6.1) in LinkedKegs. All of these were automatically installed by Homebrew as dependencies of OpenCV, and I was left wondering why the latest version of OpenCV was dependent on an older version of VTK. Initially I thought I could simply create symlinks in /usr/local/lib into the 6.1 version but soon realised there are almost 400 files. Clearly something is not right and I'm wondering if anyone here knows what needs to be done to fix this?

UPDATE I've 'fixed' #3 using a script that generates symlinks as well as a symlink to the python2.7 folder. (Code is below the error output). Whilst there were no errors during the build, this is clearly not the ideal solution but I'll see how I go for now. I think the main problem will be associated ...

edit retag close merge delete