Opened 7 years ago
Closed 7 years ago
#54820 closed defect (fixed)
missing std::trunc and other std:: math functions when building webkit2-gtk on 10.6 using macports-libsdtc++ and libgcc headers
Reported by: | kencu (Ken) | Owned by: | jeremyhu (Jeremy Huddleston Sequoia) |
---|---|---|---|
Priority: | Normal | Milestone: | |
Component: | ports | Version: | |
Keywords: | snowleopard | Cc: | dbevans (David B. Evans), MarcusCalhoun-Lopez (Marcus Calhoun-Lopez), mojca (Mojca Miklavec), kencu (Ken), Schamschula (Marius Schamschula) |
Port: | webkit2-gtk |
Description
Sorry for the long title -- try to be precise. I recently fixed webkit2-gtk
to build on older systems, but it failed on the buildbot on the setup described above, which I believe may have uncovered a cmath
flaw on that system. 10.6/libc++
worked fine, 10.6/macports-libstdc++
did not.
Initially the error was a single missing definition for std::trunc
but when I edited that in the source file to trunc()
a number of other std:: math
functions came up missing so it was a more general issue. I then tried building with gcc6
instead clang-4.0
, but same exact error in the same file (full log enclosed, clang-4.0 error was essentially identical).
Looking through the math headers, the missing function was indeed available in /opt/local/include/gcc6/c++/cmath
, but guarded by this:
#ifdef _GLIBCXX_USE_C99_MATH_TR1
Adding that definition like so add_definitions(-D_GLIBCXX_USE_C99_MATH_TR1)
to the CMakeLists.txt file quickly ran into errors for missing definitions for llrint
and similar long long definitions. This is exactly the same issue Jeremy had to fix in the libc++ math headers on 10.6, I recalled.
I took the same block from Jeremy's clang/libc++ fix, and pasted it into /opt/local/include/gcc6/c++/cmath
like so:
.... #ifndef _GLIBCXX_CMATH #define _GLIBCXX_CMATH 1 +# if __has_include(<Availability.h>) +# include <Availability.h> +# if __MAC_OS_X_VERSION_MAX_ALLOWED < 1070 +# define __APPLE_BAD_MATH_H 1 +# else +# define __APPLE_BAD_MATH_H 0 +# endif +# else +# define __APPLE_BAD_MATH_H 1 +# endif + +# if __APPLE_BAD_MATH_H +/* These prototypes are incorrectly omitted from <math.h> on Snow Leopard despite being available */ +extern "C" { + extern long long int llrintl(long double); + extern long long int llrint(double); + extern long long int llrintf(float); + + extern long long int llroundl(long double); + extern long long int llround(double); + extern long long int llroundf(float); +} +# endif +#endif // __APPLE__ // Get rid of those macros defined in <math.h> in lieu of real functions. #undef abs #undef div ....
and then webkit2-gtk proceeded to build through to completion.
- I'm not fully clear why 10.6 would need
-D_GLIBCXX_USE_C99_MATH_TR1
defined and not the others similarly building with gcc6's cmath. I can't seem to find any test or reference for this in thewebkit2-gtk
configure logic. - it appears 10.6 and lower will probably need Jeremy's fix as above in
/opt/local/include/gcc6/c++/cmath
These are easy enough to add, if this is indeed the right thing to do, in the end.
Attachments (2)
Change History (9)
Changed 7 years ago by kencu (Ken)
Attachment: | webkit2-gtk-fail-gcc.log added |
---|
Changed 7 years ago by kencu (Ken)
Attachment: | webkit2-gtk-fail-clang.log added |
---|
webkit2-gtk build failure clang -macports-libstdc++
comment:1 Changed 7 years ago by kencu (Ken)
As an aside, this is a concrete example of the kind of extra work that might be needed to support -stdlib=macports-libstdc++
instead of -stdlib=libc++
on older systems.
comment:2 Changed 7 years ago by kencu (Ken)
Cc: | jeremyhu removed |
---|---|
Owner: | set to jeremyhu, dbevans |
Status: | new → assigned |
comment:3 Changed 7 years ago by kencu (Ken)
Owner: | changed from jeremyhu, dbevans to jeremyhu |
---|
comment:4 Changed 7 years ago by Schamschula (Marius Schamschula)
Cc: | Schamschula added |
---|
comment:5 Changed 7 years ago by kencu (Ken)
Note to try:
it might be possible to fix or improve these math errors by adding a -std=c99
or -std=c11
to the build line. The missing definitions in /usr/include/architecture/i386/math.h
should then become available on 10.6 when that is defined.
On 10.6, it is guarded like so:
#if ( defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L ) || ! defined( __STRICT_ANSI__ ) || ! defined( __GNUC__ ) /* 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__ ) */
but on 10.7, the guard changes to
#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 /* !(__DARWIN_NO_LONG_LONG) */
which would explain the change in needs with the system versions 10.7+.
comment:6 Changed 7 years ago by kencu (Ken)
defining -std=c99
or -std=c11
is not something the c++ compiler will tolerate, no surprise. I tried instead to add
configure.cxxflags-append -D__STDC_VERSION__=201101L
but that ran into an error due to a weird workaround in the headers for gcc 2.95 of all things, involving a restrict
vs __restrict
name collision. The same test that would enable the long long math functions triggers that mess. Maybe there is another way around that.
I'm starting to see why Apple changed the test to __DARWIN_NO_LONG_LONG
, and why Jeremy just hardwired the definitions into <cmath> rather than sort this tangle out. I'll see if there is some tricky way through this, but hardwiring them into <cmath> for gcc6 seems like the easiest fix so far to me too.
comment:7 Changed 7 years ago by kencu (Ken)
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
attempted webkit2-gtk build on 10.6 (with gcc6; clang was essentially identical)