I have an example file:
#include <stdio.h> #include <math.h> int main(){ printf("%f\n", log(10)); }
When I compile it with gcc sample.c -oa , it works fine. I can run it with ./a and it gives output 2.302585 as expected.
However, when my file looks like this:
#include <stdio.h> #include <math.h> int main(){ double a = 10; printf("%f\n", log(a)); }
it does not compile with gcc sample.c -oa . Instead, I should use gcc sample.c -oa -lm so that I can apparently say “link math” ... What I really don't understand, why don't I link the math in the first example? And what exactly does this mean even to “connect mathematics”? It's been a while since I worked with C compilers, so forgive me if this is a bad question.
user2466999
source share