Building OpenCV as a macOS Universal Intel Binary

0

Posted by Jaime | Posted in Coding | Posted on 02-03-2017

Tags: , , , ,

OpenCV

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’ll start with that.

My build machine is running macOS 10.12 and has Xcode 8 installed on it.

OpenCV uses cmake for its build system, so you have to download and install the CMake app for macOS. I got my copy from https://cmake.org

I referred to the article listed on Wired Watershed to help me get started.

I made the following changes to the project once CMake.app was done processing the source folder.

  • Set CMAKE_OSX_ARCHITECTURES value to $(ARCHS_STANDARD_32_64_BIT)
  • Set CMAKE_OSX_DEPLOYMENT to 10.8, since my project needed it.
  • Unchecked 1394

However, when the 32-bit portion of the project went to build, it reported the following error: cap_qtkit.mm:46:9: fatal error: ‘QTKit/QTKit.h’ file not found.

Apparently, this is a known issue.

So, I thought I could solve this problem by going to version 3.2.0… off to GitHub

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.

So..

  • I unchecked WITH_LAPACK
  • I had to go into the Xcode project and set the C version to c11, and the C++ version to c++14.

Ok, things are getting better, but… the code doesn’t compile for 32-bit.

Dangit!

This can be fixed by … fixing the code?

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.

With that done, I create a pull request.

If you would like your own copy of the code I modified, you can clone the forked OpenCV repo.

A note about performance

1

Posted by Jaime | Posted in Coding | Posted on 02-08-2013

Tags: , , , ,

On a multi-core Mac, running 10.8, I ran a test to compare the speed differences of incrementing or decrementing a value with no-locks, atomics and finally, a mutex lock.

The no-lock is the baseline, and here is the difference in speed with the later 2 items:
Atomics: 3X slower on the same thread
Mutex: 7X slower on the same thread

Hmmm…

Spaces, where are you?

0

Posted by Jaime | Posted in Uncategorized | Posted on 31-08-2012

Tags: , , ,

I took me long enough to figure out how to do this, but MacLife on has it all spelled out.

Vector drawing programs

0

Posted by Jaime | Posted in Review | Posted on 26-07-2012

Tags: , ,

Matt Inman made a video where he discussed how he does his illustrations for his website: www.theoatmeal.com.

If you haven’t seen any of this stuff, I would recommend that you only do it while you are home because his site is a big productivity killer.

Anyway, it got me very interested in doing illustrations again, but I’ve usually only do that by hand and I didn’t feel like spending $800 on Illustrator.

Off to Wikipedia!

Wikipedia has a listing vector programs available; some good, some bad; some just ok. I have been using Inkscape for a while, but I’m not too crazy about it.

Then I found Sketch by Bohemian Coding.

This program fits the bill!

It’s affordable, filled with a lot of features and actually works… which unfortunately most other programs don’t do.

My only gripe with Sketch is that it cannot open SVG based drawings or Illustrator files, but that I something I leave to Inkscape to do… though I would really love Sketch to do that instead.

So if you are looking to do vector based drawing at a reasonable price, check out Sketch.

CPUID for MacOS

0

Posted by Jaime | Posted in Coding | Posted on 06-07-2012

Tags: , , , ,

This is a little old, but I wanted to share the link any for those looking for CPUID on the MacOS; download-maccpuid/

“Selectively Disable Warnings” with clang

0

Posted by Jaime | Posted in Coding | Posted on 04-04-2012

Tags: , , ,

Kick ass compiler!

I saw this demo done at WWDC on how to turn off warnings, only when truly warranted, while compiling with clang:

#if defined (__clang__)
    #pragma clang diagnostic push
    #pragma clang diagnostic ignored "-Wunused-value"
#endif // defined __clang__

void ImAUselessLittleFunction ( int pleaseUseMe )
{
    pleaseUseMe; // Nope, you are not going to be used
}
#if defined (__clang__)
    #pragma clang diagnostic pop
#endif // defined __clang__

I thought this should be shared with you… You’re welcome 🙂

File managers

0

Posted by Jaime | Posted in Review | Posted on 11-11-2011

Tags: , , , , , , ,

For the longest time, the only file manager I used on the Mac was the Finder.

I was fine with that and I never thought of needing another program.

My co-worker though uses a program named PathFinder by CocoaTech. After seeing it in action, I thought it would be a great tool for organizing my project files and it does make finding files faster and easier.

So, when I started doing more PC work for my current project, I wanted something similar to PathFinder cause the Windows Explorer is only so-so.

Well, the closest I got to PathFinder was a program called xplorer2 by zabkat.com. It’s actually very useful, and my current file organizer on my workstation.

Although it is very helpful, I wouldn’t say that it’s complete: it’s missing a few features that I like in PathFinder, like right-clicking on a file and being able to copy the full path. However, for everything else, it’s better than the Windows Explorer.

Running AppleScript commands from the Terminal.app

1

Posted by Jaime | Posted in Coding, Tip | Posted on 30-06-2011

Tags: , ,

I found some pages on the web on how to run an AppleScript from the terminal, but this seems to be the only one that works in my situation:

?View Code APPLESCRIPT
echo 'tell application "Google Chrome" to quit' | /usr/bin/osascript

In my case, my keyboard stopped working so I wanted to safely shut down the programs via ssh before I rebooted the workstation.

More fun with symbols

0

Posted by Jaime | Posted in Coding | Posted on 27-06-2011

Tags: , , , , ,

I found some very useful environment variables you can set on the application you are debugging when you need to see what symbols are being recorded by dlopen when it opens all of the libraries in your application: click on me, click on me please!

So, from your Xcode project, double click your debug app:

Double click the debug app to get to the environment variables

Now, set the following variables to YES, or NO, depending on what info you need:

There are more details on the Apple developer site

You are going to get a ton of information in the debugger console, which is very useful when trying to figure out if there are any offending symbols that could be tripping up your project.

Here is a rundown of the variables:

  • DYLD_PRINT_LIBRARIES – Logs when images are loaded.
  • DYLD_PRINT_LIBRARIES_POST_LAUNCH – Logs when images are loaded as a result of a dlopen call. Includes a dynamic libraries’ dependent libraries.
  • DYLD_PRINT_APIS – Logs the invocation that causes the dynamic loader to return the address of a symbol.
  • DYLD_PRINT_STATISTICS – Logs statistical information on an application’s launch process, such as how many images were loaded, when the application finishes launching.
  • DYLD_PRINT_INITIALIZERS – Logs when the dynamic loader calls initializer and finalizer functions.
  • DYLD_PRINT_SEGMENTS – Logs when the dynamic loader maps a segment of a dynamic library to the current process’s address space.
  • DYLD_PRINT_BINDINGS – Logs when the dynamic loader binds an undefined external symbol with its definition.

Symbol visibility in Mac OS libraries

0

Posted by Jaime | Posted in Coding | Posted on 22-10-2010

Tags: , , ,

I was having a nice coding day. Xcode was behaving nicely and all of my code seem to behave like I wanted to … then …

Crash. Okay. I can handle a crash. But. Looking at the call stack from the crash, something didn’t look right.

In the call stack there was a reference to the std::string class. But the function where the crash is happening doesn’t have any references to std::string.

What. Is. Going. On?

Okay. Time to pull up the debugging console and see what is going on.

I type “bt” in the GDB console… nothing unusual… other than the call to the phantom std::string.

So now I switch the debugger display to show both the source code and assembly code.

Nothing looks unusual stepping through the code… but… I don’t understand how std::string is being called.

I copied the Hex address where the crash is happening and back to the GDB debugger and I typed:

info shared 0X0SOMELONGHEX


To my surprise, the code had jumped to some other library that had nothing to do with my function.

Hold on here. Is this doing what I think it’s doing?

It seemed that during my application startup, one of the other dylibs that was loaded first had a reference to the same function my dylib was using, but an earlier version of the code. Both dylibs had the code statically linked in, but, they were both exposed.

Oh.

Well, that shouldn’t be too hard to fix. Just set the symbols to hidden:

GCC_SYMBOLS_PRIVATE_EXTERN = YES


Well that should have fixed my problems but I still had a lot of cleaning up to do. RTTI information was no longer easily accessible and libraries that depended on that accessible code no longer saw the symbols during the linker portion of compiling.

So, it seems that if you don’t hide your symbols, on the Mac that is, the dlopen app will match up symbols from two different libraries and pick the first one, even if they are private to the file and not exposed in any headers, causing a nice crash that produces a call stack that doesn’t make sense.

Oh. Kay. Lesson learned.