Skip to content

Instantly share code, notes, and snippets.

@command-Q
Created May 17, 2012 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save command-Q/2721440 to your computer and use it in GitHub Desktop.
Save command-Q/2721440 to your computer and use it in GitHub Desktop.
Patch against OS X 10.6 math.h fixing compilation of C++11 programs with libc++.
--- /usr/include/architecture/i386/math.h 2009-10-02 02:12:05.000000000 -0400
+++ /usr/local/include/math.h 2012-05-17 15:32:14.000000000 -0400
@@ -384,7 +384,7 @@
extern long int lround ( double );
extern long int lroundf ( float );
-#if ( defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L ) || ! defined( __STRICT_ANSI__ ) || ! defined( __GNUC__ )
+#if !(__DARWIN_NO_LONG_LONG)
/* long long is not part of C90. Make sure you are passing -std=c99 or -std=gnu99 or better if you need this. */
extern long long int llrint ( double );
@@ -393,7 +393,7 @@
extern long long int llround ( double );
extern long long int llroundf ( float );
-#endif /* #if ( defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L ) || ! defined( __STRICT_ANSI__ ) || ! defined( __GNUC__ ) */
+#endif /* !(__DARWIN_NO_LONG_LONG) */
extern double trunc ( double );
extern float truncf ( float );
@@ -479,11 +479,11 @@
extern long double roundl(long double);
extern long int lroundl(long double);
-#if ( defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L ) || ! defined( __STRICT_ANSI__ ) || ! defined( __GNUC__ )
+#if !(__DARWIN_NO_LONG_LONG)
/* long long is not part of C90. Make sure you are passing -std=c99 or -std=gnu99 or better if you need this. */
extern long long int llrintl(long double);
extern long long int llroundl(long double);
-#endif /* #if ( defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L ) || ! defined( __STRICT_ANSI__ ) || ! defined( __GNUC__ ) */
+#endif /* !(__DARWIN_NO_LONG_LONG) */
extern long double truncl(long double);
extern long double fmodl(long double, long double);
@command-Q
Copy link
Author

Fixes bug described here as provided by 10.7's libm

Can be patched into /usr/local/include without disturbing the system math.h using something like:

patch -p0 -o math.h < math.h.patch
sudo install math.h /usr/local/include

Note: This patch only applies to the x86/x86_64 math header. The math.h at /usr/include is a wrapper which conditionally includes Arm and PPC versions as well. If you need these, don't add this to /usr/local without adding an analogous wrapper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment