Re: programming in Red hat 7.2 include error without -O

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

 



And with optimization, the compiler would discover that it can compute
the sqrt at compile time and put the answer into the object code, which
is why you don't need the sqrt routine linked in with optimization
enabled.  BTW, if this is a "time killer" program, the optimized
version would run SIGNIFICANTLY faster.

Venkatesh Krishnamurthi wrote:
> 
> Hi,
> 
>   The "sqrt" function is in libm, you should use: gcc PROGRAM_NAME -lm
> 
> Venkatesh
> 
> >
> > Hi, all
> >
> > I had a function and cc it in redhat 7.2,
> > but if I use
> > $gcc PROGRAM_NAME,
> > there will be error :
> >
> > /tmp/ccAXzZTF.o: In function `main':
> > /tmp/ccAXzZTF.o(.text+0x32): undefined reference to `sqrt'
> > collect2: ld returned 1 exit status
> >
> > but if I use -O or -O2 to gcc, it works well !!
> > I do not know why, the following is source code
> >
> >
> > #include <stdio.h>
> > #include <math.h>
> >
> > int main(void)
> > {
> >
> > double pi = M_PI;
> > double pisqrt;
> > long i;
> >
> > for (i = 0; i < 10000000; ++i) {
> > pisqrt = sqrt(pi);
> > }
> > return 0;
> > }
> >
> >
> >
> > _______________________________________________
> > Redhat-devel-list mailing list
> > Redhat-devel-list@redhat.com
> > https://listman.redhat.com/mailman/listinfo/redhat-devel-list
> >
> 
> _______________________________________________
> Redhat-devel-list mailing list
> Redhat-devel-list@redhat.com
> https://listman.redhat.com/mailman/listinfo/redhat-devel-list



_______________________________________________
Redhat-devel-list mailing list
Redhat-devel-list@redhat.com
https://listman.redhat.com/mailman/listinfo/redhat-devel-list

[Index of Archives]     [Kernel Newbies]     [Red Hat General]     [Fedora]     [Red Hat Install]     [Linux Kernel Development]     [Yosemite News]

  Powered by Linux