{"id":1535,"date":"2017-03-02T16:31:02","date_gmt":"2017-03-02T21:31:02","guid":{"rendered":"http:\/\/www.jaimerios.com\/?p=1535"},"modified":"2025-12-02T23:40:59","modified_gmt":"2025-12-02T23:40:59","slug":"building-opencv-as-a-macos-universal-intel-binary","status":"publish","type":"post","link":"https:\/\/jaimerios.com\/?p=1535","title":{"rendered":"Building OpenCV as a macOS Universal Intel Binary"},"content":{"rendered":"\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/opencv.org\/assets\/theme\/logo.png\" alt=\"OpenCV\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>So, for my project, I needed an Intel Universal build of the OpenCV library.<\/p>\n\n\n\n<p>The copy of the OpenCV source I have on my machine is version 3.0.0 and it has worked well for me, so I&#8217;ll start with that.<\/p>\n\n\n\n<p>My build machine is running macOS 10.12 and has Xcode 8 installed on it.<\/p>\n\n\n\n<p>OpenCV uses cmake for its build system, so you have to download and install the CMake app for macOS. I got my copy from <a href=\"https:\/\/cmake.org\/files\/v3.8\/cmake-3.8.0-rc1-Darwin-x86_64.dmg\" target=\"_blank\" rel=\"noopener\">https:\/\/cmake.org<\/a><\/p>\n\n\n\n<p>I referred to the article listed on <a href=\"https:\/\/blogs.wcode.org\/2014\/10\/howto-install-build-and-use-opencv-macosx-10-10\/\" target=\"_blank\" rel=\"noopener\">Wired Watershed<\/a> to help me get started.<\/p>\n\n\n\n<p>I made the following changes to the project once CMake.app was done processing the source folder.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Set CMAKE_OSX_ARCHITECTURES value to $(ARCHS_STANDARD_32_64_BIT)<\/li>\n\n\n\n<li>Set CMAKE_OSX_DEPLOYMENT to 10.8, since my project needed it.<\/li>\n\n\n\n<li>Unchecked 1394<\/li>\n<\/ul>\n\n\n\n<p>However, when the 32-bit portion of the project went to build, it reported the following error: cap_qtkit.mm:46:9: fatal error: &#8216;QTKit\/QTKit.h&#8217; file not found.<\/p>\n\n\n\n<p>Apparently, this is a <a href=\"https:\/\/github.com\/Homebrew\/homebrew-science\/issues\/4303\" target=\"_blank\" rel=\"noopener\">known issue<\/a>.<\/p>\n\n\n\n<p>So, I thought I could solve this problem by going to version 3.2.0&#8230; off to <a href=\"https:\/\/github.com\/opencv\/opencv\" target=\"_blank\" rel=\"noopener\">GitHub<\/a><\/p>\n\n\n\n<p>I cloned the master branch to my machine and ran CMake again on the new source, but when I build the project with Xcode 8, I saw other problems.<\/p>\n\n\n\n<p>So..<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>I unchecked WITH_LAPACK<\/li>\n\n\n\n<li>I had to go into the Xcode project and set the C version to c11, and the C++ version to c++14.<\/li>\n<\/ul>\n\n\n\n<p>Ok, things are getting better, but&#8230; the code doesn&#8217;t compile for 32-bit.<\/p>\n\n\n\n<p>Dangit!<\/p>\n\n\n\n<p>This can be fixed by &#8230; fixing the code?<\/p>\n\n\n\n<p>Off to GitHub again, where I forked the OpenCV project and fixed the Obj-C++ code so that it will build for 32-bit Intel.<\/p>\n\n\n\n<p>With that done, I create a <a href=\"https:\/\/github.com\/opencv\/opencv\/pull\/8307\" target=\"_blank\" rel=\"noopener\">pull request<\/a>.<\/p>\n\n\n\n<p>If you would like your own copy of the code I modified, you can clone the <a href=\"https:\/\/github.com\/AhiyaHiya\/opencv\/tree\/dev_xcode_macos_universal_binary\" target=\"_blank\" rel=\"noopener\">forked OpenCV repo<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So, for my project, I needed an Intel Universal build of the OpenCV library. The copy of the OpenCV source I have on my machine is version 3.0.0 and it has worked well for me, so I&#8217;ll start with that. My build machine is running macOS 10.12 and has Xcode 8 installed on it. OpenCV &#8230; <a title=\"Building OpenCV as a macOS Universal Intel Binary\" class=\"read-more\" href=\"https:\/\/jaimerios.com\/?p=1535\" aria-label=\"Read more about Building OpenCV as a macOS Universal Intel Binary\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[251,291,335,466,506],"class_list":["post-1535","post","type-post","status-publish","format-standard","hentry","category-coding","tag-intel","tag-macos","tag-opencv","tag-universal","tag-xcode"],"_links":{"self":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/posts\/1535","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1535"}],"version-history":[{"count":1,"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/posts\/1535\/revisions"}],"predecessor-version":[{"id":1899,"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/posts\/1535\/revisions\/1899"}],"wp:attachment":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1535"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1535"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1535"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}