From: Christopher Dykes Date: Fri, 10 Mar 2017 21:52:11 +0000 (-0800) Subject: Fix problems with clock_gettime and OSX < 10.12 + XCode 8 X-Git-Tag: v2017.03.13.00~2 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=01919b98fd78769d8e73dc2c0f959743393e886e;p=folly.git Fix problems with clock_gettime and OSX < 10.12 + XCode 8 Summary: It's a pain, so rely on macros to figure a few things about the build configuration. Reviewed By: yfeldblum Differential Revision: D4229128 fbshipit-source-id: 78b414c21cae6ba51ade2ab75b117cccad5c608c --- diff --git a/folly/portability/Time.cpp b/folly/portability/Time.cpp index 237bc9e3..dec1daf4 100755 --- a/folly/portability/Time.cpp +++ b/folly/portability/Time.cpp @@ -32,7 +32,7 @@ static void duration_to_ts( .count()); } -#if !FOLLY_HAVE_CLOCK_GETTIME +#if !FOLLY_HAVE_CLOCK_GETTIME || FOLLY_FORCE_CLOCK_GETTIME_DEFINITION #if __MACH__ #include #include diff --git a/folly/portability/Time.h b/folly/portability/Time.h index 708a5faf..0ed24a27 100755 --- a/folly/portability/Time.h +++ b/folly/portability/Time.h @@ -21,6 +21,25 @@ #include +// OSX is a pain. The XCode 8 SDK always declares clock_gettime +// even if the target OS version doesn't support it, so you get +// an error at runtime because it can't resolve the symbol. We +// solve that by pretending we have it here in the header and +// then enable our implementation on the source side so that +// gets linked in instead. +#if __MACH__ && ( \ + MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12 || \ + __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_10_0) + +# ifdef FOLLY_HAVE_CLOCK_GETTIME +# undef FOLLY_HAVE_CLOCK_GETTIME +# endif + +# define FOLLY_HAVE_CLOCK_GETTIME 1 +# define FOLLY_FORCE_CLOCK_GETTIME_DEFINITION 1 + +#endif + // These aren't generic implementations, so we can only declare them on // platforms we support. #if !FOLLY_HAVE_CLOCK_GETTIME && (defined(__MACH__) || defined(_WIN32))