sbc@informatics.wustl.edu (Steve Cousins) (05/17/91)
I'm having a lot of trouble tracking down a bug, which only comes up when
my code is linked in to ATK. The following program works fine:
#include <math.h>
main()
{
int bigN = 4181;
int ndocs = 4;
double log_val;
log_val = log((double)bigN/(double)ndocs);
printf("log(%f/%f) = %f or %f\n",
(double)bigN, (double)ndocs, log_val,
log((double)bigN/(double)ndocs));
}
when compiled with "cc foo.c -lm" or with "gcc foo.c -lm" on either a
Sparcstation 330 with SunOS 4.1 or a Sparcstation 470 with SunOS 4.1.1.
(I've tried all the experiments I'll describe on both of these platforms).
When I include this code segment in an ATK program, things act very strangly.
The correct answer is:
log(4181.000000/4.000000) = 6.952011 or 6.952011
From the ATK version I get
log(4181.000000/4.000000) = 1072715008.000000 or 1.020752
and if (in the ATK version) I move that calculation of the log from the
last arg to printf to the first argument after the control string, I get:
log(1.020752/0.000000) = 0.000000 or -0.000000
This tells me that maybe log is returning something of a different length
than the C compiler thinks. Anyway, it's very frustrating because I got
the code to work standalone, but can't seem to embed it in the ATK application.
My Imakefile has the line:
DynamicMultiObject(searchv.do, searchv.o, /usr/desert/sybase/lib/libsybdb.a, -lm)
which generates the commands:
rm -f searchv.o
cc -c -I. -I/usr/desert/sybase/include/ -g -I/usr/andrew/include/atk -I/usr/andrew/include -I//usr/include/X11 searchv.c
/usr/desert/sybase/include//sybfront.h: 164: MAX redefined
/usr/desert/sybase/include//sybfront.h: 165: MIN redefined
/usr/andrew/bin/makedo -g -d /usr/andrew/lib -b /usr/andrew/bin -o searchv.do searchv.o /usr/desert/sybase/lib/libsybdb.a -lm
doindex: indexing searchv.do ...OK
doindex: Writing index file...Done
Can anyone see anything I'm doing that's obviously wrong? What
version of "log" is getting called? Any help is appreciated, as I'm
at a loss as to how to proceed at this point.
Thanks
Steve Cousins
Medical Informatics Laboratory
Washington University
St. Louis, MO
gk5g+@ANDREW.CMU.EDU (Gary Keim) (05/17/91)
Excerpts from misc: 16-May-91 wierd behavior Steve Cousins@informatic (2139) > I'm having a lot of trouble tracking down a bug, which only comes up when > my code is linked in to ATK. The following program works fine: First, I tested your code in a dynamically loaded object and it worked as expected. The sybase library must be the culprit. Does it contain any math functions? Try % nm /usr/desert/sybase/lib/libsybdb.a | egrep log. If it does contain log, you may want to blow off the -lm. One solution may be to rewrite the last two arguments to the DynamicObject() rule, making sure to list the standard math library first: DynamicObject(searchv,, -lm -L/usr/desert/sybase/lib -lsybdb) Give it a try. Gary Keim ATK Group