Jeroen Demeyer on Mon, 14 Sep 2009 11:24:28 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Problems with has_log2.c and has_exp2.c


Hello all,

I had a problem compiling sage-4.1.1 with gcc-4.5.0 and it could be traced back to a problem in PARI's Configure programs has_log2.c and has_exp2.c (which are the same for pari-2.3.3 and pari-SVN).

The short story is that I would propose to change these configure programs to something like:

#include <math.h>
int main()
{
  double x = log2(2.0);
  return 0;
}


Now the long story of why:

On my system, the functions log2() and exp2() only exist when compiling C99 or C++ code. Not C89, which is still the default for gcc:

$ gcc -lm -o has_exp2 has_exp2.c
has_exp2.c:2: error: 'exp2' undeclared here (not in a function)

$ gcc -std=c99 -lm -o has_exp2 has_exp2.c
has_exp2.c:2: warning: initialization from incompatible pointer type
has_exp2.c: In function 'main':
has_exp2.c:3: warning: comparison of distinct pointer types lacks a cast

$ g++ -lm -o has_exp2 has_exp2.c
has_exp2.c:2: error: invalid conversion from 'double (*)(double)throw ()' to 'char (*)()'
has_exp2.c: In function 'int main()':
has_exp2.c:3: error: comparison between distinct pointer types 'char (*)()' and 'double (*)(double)throw ()' lacks a cast

Note that the configure program really does a bad job on C++ code, because the function exp2() exists but Configure thinks that it does not exist. This causes paricom.h to declare exp2() in a different way from <math.h> which then gives an error:

In file included from ../src/headers/pari.h:50:0,
                 from ../src/gp/gp.c:21:
../src/headers/paricom.h: In function 'double exp2(double)':
../src/headers/paricom.h:94:33: error: new declaration 'double exp2(double)'
/usr/include/bits/mathcalls.h:142:1: error: ambiguates old declaration 'double exp2(double)'
../src/headers/paricom.h: In function 'double log2(double)':
../src/headers/paricom.h:102:33: error: new declaration 'double log2(double)' /usr/include/bits/mathcalls.h:145:1: error: ambiguates old declaration 'double log2(double)'
../src/gp/gp.c: In function 'char* what_readline()':
../src/gp/gp.c:776:7: warning: deprecated conversion from string constant to 'char*'

The problem with sage is even more subtle, because it mixes C and C++ code. I have not analyzed exactly what changed in gcc-4.5.0.


I would also propose that config/get_cc checks for a "-std=gnu99" or "-std=c99" option for the C compiler and adds it when compiling PARI.


Cheers,
Jeroen.