GNOME Bugzilla – Bug 128136
plugins/fn-math/functions.c doesn't compile on NetBSD/sparc-1.5
Last modified: 2004-12-22 21:47:04 UTC
This is a followup of bug #124951 I got the following compile error in Gnumeric 1.2.2 on NetBSD/sparc-1.5: <-- snip --> ... -Wall -Wmissing-prototypes -Wsign-compare -Wpointer-arith -Wnested-externs -Wchar-subscripts -Wwrite-strings -D_POSIX_SOURCE -D__EXTENSIONS__ -D_BSD_SOURCE -c functions.c -fPIC -DPIC -o .libs/functions.o functions.c:923: warning: #warning improve error handling. Relying on value_new_float to do it is cheesy functions.c: In function `gnumeric_acosh': functions.c:338: warning: implicit declaration of function `acosh' functions.c: In function `gnumeric_asinh': functions.c:395: warning: implicit declaration of function `asinh' functions.c: In function `gnumeric_atanh': functions.c:453: warning: implicit declaration of function `atanh' functions.c: In function `gnumeric_fact': functions.c:888: warning: implicit declaration of function `lgamma' functions.c:889: `signgam' undeclared (first use in this function) functions.c:889: (Each undeclared identifier is reported only once functions.c:889: for each function it appears in.) gmake[3]: *** [functions.lo] Error 1 gmake[3]: Leaving directory `/aux/adrian/build/gnumeric-1.2.2/plugins/fn-math' <-- snip -->
This one looks like your c library is deficient. Please have a look at "man lgamma" and see what it says about the sign of the gamma function.
The problem is, that the Gnumeric configure script adds -D_POSIX_SOURCE to the CFLAGS without adding a -D_XOPEN_SOURCE From /usr/include/math.h (note that on NetBSD 1.5 _POSIX_SOURCE implicitely defines _POSIX_C_SOURCE): <-- snip --> ... /* * XOPEN/SVID */ #if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) || \ defined(_XOPEN_SOURCE) #define M_E 2.7182818284590452354 /* e */ #define M_LOG2E 1.4426950408889634074 /* log 2e */ #define M_LOG10E 0.43429448190325182765 /* log 10e */ #define M_LN2 0.69314718055994530942 /* log e2 */ #define M_LN10 2.30258509299404568402 /* log e10 */ #define M_PI 3.14159265358979323846 /* pi */ #define M_PI_2 1.57079632679489661923 /* pi/2 */ #define M_PI_4 0.78539816339744830962 /* pi/4 */ #define M_1_PI 0.31830988618379067154 /* 1/pi */ #define M_2_PI 0.63661977236758134308 /* 2/pi */ #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ #define MAXFLOAT ((float)3.40282346638528860e+38) extern int signgam; #endif /* !_ANSI_SOURCE && !_POSIX_C_SOURCE || _XOPEN_SOURCE */ ... #if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) || \ defined(_XOPEN_SOURCE) double erf __P((double)); double erfc __P((double)); double gamma __P((double)); double hypot __P((double, double)); int isnan __P((double)); int finite __P((double)); double j0 __P((double)); double j1 __P((double)); double jn __P((int, double)); double lgamma __P((double)); double y0 __P((double)); double y1 __P((double)); double yn __P((int, double)); ... <-- snip -->
This might become ugly... In configure.in, try adding this before line 214: # That, unfortunately, turns off stuff on NETBSD. AC_MSG_CHECKING([whether -D_XOPEN_SOURCE is needed for signgam]) AC_TRY_COMPILE([#include <math.h>], [if ((lgamma(-1.5),signgam) == 0);], need_xopen=no, need_xopen=yes) AC_MSG_RESULT($need_xopen) if test $need_xopen = yes ; then CFLAGS="$CFLAGS -D_XOPEN_SOURCE" fi jody: have a look around current line 214. Isn't that an awful mess between need_ext and need_posix?
This would most likely work, but let me point to a problem in this code: if test $need_xopen = yes ; then CFLAGS="$CFLAGS -D_XOPEN_SOURCE" fi If the sgngam test fails for a different reason, -D_XOPEN_SOURCE is defined without being needed. This needs to be something like if test $need_xopen = yes ; then CFLAGS="$CFLAGS -D_XOPEN_SOURCE" else AC_MSG_ERROR([sgngam is not available]) fi After thinking about it, it seems a similar bug causes the -D_POSIX_SOURCE that is the source of the NetBSD problems: Look at the fdopen check in configure.in and the following from my config.log: <-- snip --> ... configure:20727: checking whether -D_POSIX_SOURCE is needed for fdopen configure:20747: gcc -c -O2 -mcpu=v8 -Wall -Wmissing-prototypes -Wsign-compare -Wpointer-arith -Wnested-externs -Wchar-subscripts -Wwrite-strings -Werror conf test.c >&5 cc1: warnings being treated as errors conftest.c: In function `main': conftest.c:28: warning: unused variable `f' configure:20753: $? = 1 configure: failed program was: | /* confdefs.h. */ | | #define PACKAGE_NAME "gnumeric" | #define PACKAGE_TARNAME "gnumeric" | #define PACKAGE_VERSION "1.2.2" | #define PACKAGE_STRING "gnumeric 1.2.2" | #define PACKAGE_BUGREPORT "http://bugzilla.gnome.org/enter_bug.cgi?product=gnu meric" | #define PACKAGE "gnumeric" | #define VERSION "1.2.2" | #define STDC_HEADERS 1 | #define HAVE_SYS_TYPES_H 1 | #define HAVE_SYS_STAT_H 1 | #define HAVE_STDLIB_H 1 | #define HAVE_STRING_H 1 | #define HAVE_MEMORY_H 1 | #define HAVE_STRINGS_H 1 | #define HAVE_INTTYPES_H 1 | #define HAVE_UNISTD_H 1 | #define HAVE_DLFCN_H 1 | #define STDC_HEADERS 1 | #define WITH_BONOBO 1 | #define HAVE_LIBGNOMEDB 1 | /* end confdefs.h. */ | #include <stdio.h> | int | main () | { | FILE *f = fdopen(1, "r") | ; | return 0; | } configure:20776: result: yes ... <-- snip --> WTF does the fdopen test add a -Werror to the CFLAGS, and then this test fails because of an unused variable??? A check whether the same compilation works with -D_POSIX_SOURCE and an AC_MSG_ERROR if it doesn't would have caught this bug. Would you accept a patch to remove the -Werror from the fdopen check and to add some AC_MSG_ERRORs?
That -Werror probably comes from deep inside autoconf code. Don't try to mess with that -- it's messy. However, you might get away with adding "(void)f;" after the declaration to make gcc see it as used. (And you're right that my proposed patch is too simplistic, but fixing it would require another compilation test with -D_XOPEN_SOURCE.)
No, the -Werror is explicitely added in configure.in: <-- snip --> ... AC_MSG_CHECKING([whether -D_POSIX_SOURCE is needed for fdopen]) saved_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS -Werror" AC_TRY_COMPILE([#include <stdio.h>], [FILE *f = fdopen(1, "r")], need_posix=no, need_posix=yes) ... <-- snip --> I'm currenttly working on a patch that should fix all these issues properly.
Hmm..., so it is. That's bogus as the compiler might not understand -Werror. CC might not be gcc. However, be careful! The test needs to fail if there is no prototype for fdopen. It is not enough that the library has the function. Thus simply removing "-Werror" will not work right.
Created attachment 21931 [details] [review] proposed fix
My proposed fix does the following: - use AC_CHECK_DECL for the fdopen check - AC_MSG_ERROR if we don't know how to compile one of fdopen, struct timeval, M_PI, caddr_t
Visually looks good. I'll test Solaris in a few days. Someone else needs to test Linux.
*** Bug 128123 has been marked as a duplicate of this bug. ***
*** Bug 128124 has been marked as a duplicate of this bug. ***
Patch tested on linux. Works fine
Not so fast: <JHM> checking whether fdopen is declared... no <JHM> configure: adding -D_POSIX_SOURCE to CFLAGS <JHM> checking whether fdopen is declared... (cached) no <JHM> configure: error: fdopen is not available <JHM> make: *** [configure-stamp] Error 1 <JHM> The patch is a no-go on Linux.
I can't reproduce this problem on Linux. Could you post the relevant parts of the config.log?
Created attachment 21997 [details] [review] updated patch (after discussion on irc with gmorten and JHM)
this patch works for me on linux too
Confirmed on solaris. Fixed in cvs.