引用math.h的时候,数学函数报错为未定义的符号

undefined reference to `log10'
undefined reference to `floor'
 undefined reference to `pow‘

搜了一下,原来是在编译的是没有没有引用数学函数的函数库导致的,在gcc yoursourcefile.c 的时候加上' -lm' 就好了 "gcc -lm yoursourcefile.c" 编译通过

参考:http://stackoverflow.com/questions/6534191/undefined-reference-to-only-some-math-h-functions

The linker isn't complaining about pow((double) 2, (double) 3) because the compiler is replacing it with a constant 8.0. You shouldn't depend on this behavior; instead, you should always use the -lm option properly. (BTW, that's more clearly written as pow(2.0, 3.0).

Consider the following program:

#include 
#include 
int main(void) {
    double x = 0.1;
    printf("%g\n", pow(2.0, 3.0));
    printf("%g\n", asin(x));
    return 0;
}

When I compile a

你可能感兴趣的:(linux,C,C,math.h,数学,c)