math.h - Using pow() function throws undefined reference error in C -


why following bit of code work in c:

int res = pow(2, 3); printf("%d\n", res); 

while other doesn't?

int = 2; int b = 3;  int res = pow(a, b); printf("%d\n", res); 

even if try

double = 2; double b = 3;  double res = pow(a, b); printf("%f\n", res); 

i an

undefined reference `pow'

what doing wrong?

when works, it's because calculation done compiler (and included in binary if wrote out)

printf("8\n"); 

when doesn't work, because pow function included in math library , math library isn't linked binary default.
math library linked, if compiler gcc, use

gcc ... -lm ... 

with other compilers, should same :)
read documentation


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -