Is log10f () not part of the standard math library?

I am having problems using log10f (). I am compiling a program on Linux (2.6.28-11-generic) and using gcc (3.4.6).

The following source compiles and prints 1.000000 on run.

#include <stdio.h>
#include <math.h>

int main() {
   printf("%f\n", log10f(10));
   return 0;
}

      

while the bottom one does not and throws a link error:

#include <stdio.h>
#include <math.h>

int main() {
   printf("%f\n", log10f(100));
   return 0;
}

      

Error: Undefined reference to log10f

  • Is log10f () undefined as part of the standard math library (the male pages indicate it is part of the math library)?

  • Why doesn't the second example compile?

+1


a source to share


1 answer


This is because the required library is not automatically linked to the executable. libm.a



You have to add a parameter to gcc. Then the linker will link to your executable as well . -lm

libm.a

+5


a source







All Articles