I have tried several different ways to compile OpenCV on the Mac in order to get it to work on a computer older than mine but have not been successful. My application is and has been running for months on 50+ Macs but they are all Late 2013 Macbooks or newer. I have confirmed that it runs on older operating systems. For example, I run High Sierra 10.13 but I have seen my application run on a system with 10.10.5 and 10.12 systems. Even Early 2013 Macbooks don't run my application. My goal is to get the application to run on older Macs than mine which is a Late 2013 Macbook Pro.
I use Xcode 9.2. I use brew to compile OpenCV. In this example, I was using opencv 3.4.0. I also tried 3.4.1 and it didn't work either. I'm sure I'm missing some simple setting.
I currently compile with this setting but it is not enough:
-DCMAKE_OSX_DEPLOYMENT_TARGET=10.9
I tried compiling with this flag but it didn't help. i thought this flag would tell the compiler to target an older architecture but it didn't work:
-DCMAKE_CXX_COMPILER_TARGET=x86_64-apple-darwin15.5.0
the crash log from the Macbook from 2010 looks like this:
Process: Brightday [17622]
Path: /Users/USER/Downloads/Brightday.app/Contents/MacOS/Brightday
Identifier: com.brightday.Brightday
Version: 47 (47)
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: Brightday [17622]
User ID: 502
Date/Time: 2018-01-22 17:46:07.436 -0800
OS Version: Mac OS X 10.11.5 (15F34)
Report Version: 11
Anonymous UUID: 333100CF-2D55-443A-78BE-49F842AC3DD4
>
Sleep/Wake UUID: B8FBAF9B-42C4-450F-905D-74EAE4B19AD9
>
Time Awake Since Boot: 600000 seconds
Time Since Wake: 5100 seconds
>
System Integrity Protection: enabled
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_BAD_INSTRUCTION (SIGILL)
Exception Codes: 0x0000000000000001, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
>
Application Specific Information: /Users/xxxxx-peter/Downloads/Brightday.app/Contents/MacOS/../Frameworks/../Frameworks/opencv/libopencv_core.3.4.0.dylib
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libopencv_core.3.4.0.dylib 0x000000010f8e7556 _GLOBAL__sub_I_persistence.cpp + 44
1 dyld 0x00007fff6606510b ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) + 265
2 dyld 0x00007fff66065284 ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) + 40
3 dyld 0x00007fff660618bd ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 305
4 dyld 0x00007fff66061852 ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 198
5 dyld 0x00007fff66061743 ImageLoader::processInitializers(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 127
6 dyld 0x00007fff660619b3 ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) + 75
7 dyld 0x00007fff660540f1 dyld::initializeMainExecutable() + 208
8 dyld 0x00007fff66057d98 dyld::_main(macho_header const, unsigned long, int, char const, char const, char const, unsigned long) + 3596
9 dyld 0x00007fff66053276 dyldbootstrap::start(macho_header const, int, char const, long, macho_header const, unsigned long*) + 512
10 dyld 0x00007fff66053036 _dyld_start + 54
>
Thread 0 crashed with X86 Thread State (64-bit): rax: 0x000000011003b6d1 rbx: 0x00007fff50563650 rcx: 0x00007fff50566d40 rdx: 0x00007fff50566ce0 rdi: 0x0000000000000001 rsi: 0x00007fff50566cd0 rbp: 0x00007fff505636c0 rsp: 0x00007fff50563650 r8: 0x00007fff6608b630 r9: 0x000000000000002c r10: 0x00007fff50566d38 r11: 0x0000000000000000 r12: 0x00000001102758e8 r13: 0x00007fff6608b568 r14: 0x00007fff66093b78 r15: 0x0000000000000001 rip: 0x000000010f8e7556 rfl: 0x0000000000010246 cr2: 0x000000010f8e752a
Logical CPU: 2 Error Code: 0x00000000 Trap Number: 6
Binary Images: 0x10f699000 - 0x10f71bfff +com.brightday.Brightday (47 - 47) /Users/USER/Downloads/Brightday.app/Contents/MacOS/Brightday 0x10f75d000 - 0x110274fe7 +libopencv_core.3.4.0.dylib (0) /Users/USER/Downloads/Brightday.app/Contents/Frameworks/opencv/libopencv_core.3.4.0.dylib 0x1103ec000 - 0x11047bfef +libopencv_features2d.3.4.0.dylib (0) /Users/USER/Downloads/Brightday.app/Contents/Frameworks/opencv/libopencv_features2d.3.4.0.dylib 0x1104ae000 - 0x1104e8ffb +libopencv_flann.3.4.0.dylib (0) /Users/USER/Downloads/Brightday.app/Contents/Frameworks/opencv/libopencv_flann.3.4.0.dylib
Here's the output from
brew edit opencv
class Opencv < Formula
desc "Open source computer vision library"
homepage "https://opencv.org/"
url "https://github.com/opencv/opencv/archive/3.4.1.tar.gz"
sha256 "ac627047c2afbbcb0ddd9583342f03c8e700032c9a77721a52c39c9d96790dbb"
bottle do
sha256 "e076e80bc5fe389bab1a8c1ba767fe737d4143b832830829681b5114203f0a78" => :high_sierra
sha256 "afac0a89c93c20e90b28292a72a91d088ef03b528f82ed01679f92df6696e56c" => :sierra
sha256 "639b043ae297109902edea2a6fcfff7da74caed73f3e5a5cc0fddf9743dc8fbe" => :el_capitan
end
depends_on "cmake" => :build
depends_on "pkg-config" => :build
depends_on "eigen"
needs :cxx11
resource "contrib" do
url "https://github.com/opencv/opencv_contrib/archive/3.4.1.tar.gz"
sha256 "298c69ee006d7675e1ff9d371ba8b0d9e7e88374bb7ba0f9d0789851d352ec6e"
end
def install
ENV.cxx11
resource("contrib").stage buildpath/"opencv_contrib"
args = std_cmake_args + %W[
-DCMAKE_OSX_SYSROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk
-DCMAKE_OSX_DEPLOYMENT_TARGET=10.9
-DBUILD_opencv_aruco=OFF
-DBUILD_opencv_bgsegm=OFF
-DBUILD_opencv_bioinspired=OFF
-DBUILD_opencv_calib3d=OFF
-DBUILD_opencv_ccalib=OFF
-DBUILD_opencv_dpm=OFF
-DBUILD_opencv_face=OFF
-DBUILD_opencv_fuzzy=OFF
-DBUILD_opencv_img_hash=OFF
-DBUILD_opencv_line_descriptor=OFF
-DBUILD_opencv_optflow=OFF
-DBUILD_opencv_phase_unwrapping=OFF
-DBUILD_opencv_reg=OFF
-DBUILD_opencv_rgbd=OFF
-DBUILD_opencv_saliency=OFF
-DBUILD_opencv_shape=OFF
-DBUILD_opencv_stereo=OFF
-DBUILD_opencv_stitching=OFF
-DBUILD_opencv_structured_light=OFF
-DBUILD_opencv_superres=OFF
-DBUILD_opencv_surface_matching=OFF
-DBUILD_opencv_videostab=OFF
-DBUILD_opencv_xfeatures2d=OFF
-DBUILD_opencv_ximgproc=OFF
-DBUILD_opencv_xobjdetect=OFF
-DBUILD_opencv_xphoto=OFF
-DCMAKE_BUILD_TYPE=RELEASE
-DWITH_OPENMP=ON
-DWITH_IPP=ON
-DWITH_NVCUVID=ON
-DBUILD_opencv_cudaarithm=ON
-DBUILD_opencv_cudafilters=ON
-DBUILD_opencv_cudaimgproc=ON
-DBUILD_opencv_cudafeatures2d=ON
-DWITH_CUDA=ON
-DENABLE_FAST_MATH=1
-DCUDA_FAST_MATH=1
-DWITH_CUBLAS=1
-DWITH_CUFFT=1
-DWITH_CSTRIPES=ON
-DBUILD_JASPER=OFF
-DBUILD_JPEG=ON
-DBUILD_OPENEXR=ON
-DBUILD_PERF_TESTS=OFF
-DBUILD_PNG=ON
-DBUILD_TESTS=OFF
-DBUILD_TIFF=ON
-DBUILD_ZLIB=OFF
-DBUILD_opencv_java=OFF
-DOPENCV_ENABLE_NONFREE=OFF
-DOPENCV_EXTRA_MODULES_PATH=#{buildpath}/opencv_contrib/modules
-DWITH_1394=OFF
-DWITH_EIGEN=ON
-DWITH_FFMPEG=OFF
-DWITH_GPHOTO2=OFF
-DWITH_GSTREAMER=OFF
-DWITH_JASPER=OFF
-DWITH_OPENEXR=ON
-DWITH_OPENGL=OFF
-DWITH_QT=OFF
-DWITH_TBB=ON
-DWITH_VTK=OFF
-DBUILD_opencv_python2=OFF
-DBUILD_opencv_python3=OFF
-DCPU_BASELINE=SSE2
-DCPU_DISPATCH=SSE4_2,AVX2
]
if build.bottle?
args += %w[-DCPU_BASELINE=SSE2 -DCPU_DISPATCH=SSE4_2,AVX]
end
mkdir "build" do
system "cmake", "..", *args
system "make"
system "make", "install"
end
end
test do
(testpath/"test.cpp").write <<~EOS
#include <opencv/cv.h>
#include <iostream>
int main() {
std::cout << CV_VERSION << std::endl;
return 0;
}
EOS
system ENV.cxx, "test.cpp", "-I#{include}", "-L#{lib}", "-o", "test"
assert_equal `./test`.strip, version.to_s
["python", "python3"].each do |python|
output = shell_output("#{python} -c 'import cv2; print(cv2.__version__)'")
assert_equal version.to_s, output.chomp
end
end
end