Tuesday, July 10, 2012

Getting monotonic time on OS X since clock_gettime isn't available

tl;dr version:
  1. #include <mach/mach_time.h> into your source file.
  2. replace any calls to clock_gettime(CLOCK_MONOTONIC, &timespec_t) with calls to mach_absolute_time().
One of the great things about OS X is that so many things 'just work', especially as regards open-source software. That's because a lot of open source developers put in the time needed to make their software work on as many platforms as possible. Once in a while, though, you encounter some software written for Linux that doesn't work on OS X. I needed the ability to capture and verify fingerprints, and I had a couple of avenues open to me. Nyimbi Odero (who headed the team that developed the biometric capture software for Nigeria's 2011 elections) recommended the use of libfprint for capturing the fingerprint data. So I went off and grabbed libfprint, unpacked and did the ./configure dance. It complained about not having a dependency, I would look up the dependency in HomeBrew and install it. After about 4 or 5 direct dependencies were installed using HomeBrew, configure completed without errors. make was throwing up errors involving CLOCK_MONOTONIC. Initially, I took one glance and began looking that up (I need to really slow down a lot more and look at things properly). I didn't find anything useful and put the issue aside for a bit. I later ran make distclean, re-ran configure, and then make. Looking at the error closer this time, I saw that clock_gettime() was 'implicitly declared'. So I googled again and found the information at the top. I would normally have directly linked, but I couldn't view the actual page (referenced several times since 2009 when it was actually posted), since there was a database error on the site.

Disclaimer: I still have no idea what monotonic time is.

No comments: