I am coding under GNU/Linux Debian 8.5
I have a simple program.
If I compile this with gcc prog.c
it is OK!
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
int main(int argc, char const *argv[]) {
float _f = 3.1415f;
floor(_f);
ceil(_f);
return 0;
}
Bud if I add pow()
, it says that it cannot find pow
and I need to add gcc prog.c -lm
to make it right.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
int main(int argc, char const *argv[]) {
float _f = 3.1415f;
floor(_f);
ceil(_f);
pow(_f, 2);
return 0;
}
If I am right, the pow()
, ceil()
, floor()
are all from <math.h>
?
So why don't floor()
and ceil()
throw a compilation error, and pow()
does, without -lm
flag?