gpt4 book ai didi

c - C 中的 pow 函数

转载 作者:太空狗 更新时间:2023-10-29 16:50:55 25 4
gpt4 key购买 nike

我编写了一个 C 代码,它具有来自 math.h 库的幂函数。当我编译我的程序时,我收到一个错误,即“未定义对‘pow’函数的引用”,我使用 gcc 编译器 (fedora 9) 编译我的程序。

然后我将 -lm 标志插入 gcc,错误被忽略但 pow 函数的输出为 0。

#include<math.h>
main()
{
double a = 4, b = 2;
b = pow(b,a);
}

谁能帮帮我?我的编译器有问题吗??

谢谢。

最佳答案

对于其他寻求此类答案的人:

这行不通:

gcc my_program.c -o my_program

它会产生这样的东西:

/tmp/cc8li91s.o: In function `main':
my_program.c:(.text+0x2d): undefined reference to `pow'
collect2: ld returned 1 exit status

这会起作用:

gcc my_program.c -o my_program -lm

关于c - C 中的 pow 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10774177/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com