Bill Allombert on Wed, 05 May 2004 13:31:25 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: link error log2 exp2 gcc 3.4.0 and resolution |
On Sun, Apr 25, 2004 at 04:36:21PM -0700, Carl Hansen wrote: > a bug, and its resolution > > 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. 2) That does not check whether the prototype for log2 exists, only if the log2 symbol is in the library. glibc has log2 but it provide an prototype for it only in c99 mode (that might be a bug, I would expect c89 to have log2.) So apparently this is working only by chance (problem 1 compensating for problem 2). On top of that, apparently gcc 3.4/3.5 precompute log2(1.0) so don't need -lm to pass that test. Cheers, Bill.