Karim Belabas on Wed, 05 May 2004 21:27:05 +0200


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

Re: link error log2 exp2 gcc 3.4.0 and resolution


* Bill Allombert [2004-05-05 13:31]:
>> just installed gcc 3.4.0 (on Solaris 9 sparc)
>>
>> couldn't remake, link errors:
>> Undefined  symbol   exp2   log2
>>
>> examining pari-2.2.7.alpha/config/has_log2.c,
>> (which is used by Configure) :
>>
>>
>> #include <math.h>
>> main(){ double x=log2(1.0); }
>>
>> compiles cleanly,
>>
>> however trying:
>>
>> #include <math.h>
>> main(){ double x=log2(0.666); }
>>
>> get        Undefined  symbol   log2
>>
>>
>> Having pondered, conclude the compiler compile-time-optimises
>> log2(1.0)  to 0 , so log2 is never  called at runtime, as
>> can be verified by looking at has_log2.s , so the Configure script
>> will conclude has it HAS log2, whereas  in  the
>> other case log2(0.666), Configure script will realise
>> we  in fact DON'T have log2.
>>
>> likewise has_exp2.c
>>
>> So contemplate  assumptions made by compiler, compiler writer, writer
>> of Configure, and become wise, and wonder what else could be wrong.
>
> I have studied the problem on i386-linux, glibc 2.3.2.ds1-12 and
> both gcc 3.3.3 and a snapshot of 3.5.0 (I don't have 3.4.0 at hand).
>
> Apparently the way PARI check for log2 is broken.
> PARI try to compile and link a simple program using log2 but:
>
> 1) It does not specify -lm, so it fails.

Good point. I've added the missing -lm to the extra_flags for these tests.

> 2) That does not check whether the prototype for log2 exists, only
>    if the log2 symbol is in the library.

This is correct, that's all we want. We do not want to try and work around
unknown, possibly broken or conflicting, headers. The autoconf way to do
things is even more paranoid:

  #ifdef __cplusplus
  extern "C"
  #endif
  /* We use char because int might match the return type of a gcc2
     builtin and then its argument prototype would still apply.  */
  char fun ();
  int main () { fun (); return 0; }

Anyway, it's quite unimportant to "miss" either exp2 or log2: both are
almost unused.

    Karim.
--
Karim Belabas                     Tel: (+33) (0)1 69 15 57 48
Dep. de Mathematiques, Bat. 425   Fax: (+33) (0)1 69 15 60 19
Universite Paris-Sud              http://www.math.u-psud.fr/~belabas/
F-91405 Orsay (France)            http://pari.math.u-bordeaux.fr/  [PARI/GP]