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

编程入门 行业动态 更新时间:2024-10-26 01:25:35

引用math.h的时候,数学函数<a href=https://www.elefans.com/category/jswz/34/1771188.html style=报错为未定义的符号"/>

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

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

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

参考:

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 <stdio.h>
#include <math.h>
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

更多推荐

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

本文发布于:2024-02-25 01:53:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1697395.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:报错   函数   符号   数学   未定义

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!