-
pow
Hi,
The following is my code. When I tried to compile it. It give me an error massage "undefined reference to 'pow'. I thought I did include #include <math.h>....
Any idea?
Thanks.
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main(){
int i;
float s, l;
printf("\n\t|----------------------------------------------------|");
printf("\n\t| x | x^2 | cube root of x | x^4 |");
printf("\n\t|----------------------------------------------------|");
for (i=1;i<=100;i++)
{
s = i*i;
l = s*s;
printf("\n\t| %d |",i);
printf(" %5.0f |",s);
printf(" %5.3f |",pow(i,1.0/3.0));
printf(" %5.0f |",l);
printf("\n");
getch();
}
printf("\t|-----------------------------------------------------|");
getch();
}
-
Re: pow
As far as I remember, pow() returns a double value, so instead of %f use %lf.
-
Re: pow
still...
/tmp//ccg24629.o: In function `main':
/tmp//ccg24629.o(.text+0xaf): undefined reference to `pow'
collect2: ld returned 1 exit status
-
Re: pow
You need to link against the math library, libm. Add -lm to the compiler command line.
-
Re: pow
like this #include <libm.h>?
I though this #include <math.h> should do it.
-
Re: pow
No, not like this. You need to learn the difference between a library file and a header file. I explicitly said 'command line', too, and what you must put there.
-
Re: pow