“对‘pow’的未定义引用”是什么意思?

问题描述

#include <stdio.h>
#include <math.h>

main()
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    double ans= pow(a,b);
    printf("%f",ans);
    
}

我编写了这段代码并尝试在 Visual stdio (linux) 中运行。但它给出了一条错误消息

msg- new_year_candles.c:4:1: warning: return type defaults to ‘int’ [-Wimplicit-int] 4 | main() | ^~~~ /usr/bin/ld: /tmp/ccCQbbLV.o: in function `main': new_year_candles.c:(.text+0x4a): undefined reference to `pow' collect2: error: ld returned 1 exit status

现在该怎么办?

解决方法

使用链接 -lm 编译,例如

gcc -o demo demo.c -lm

如果您查看 pow 中的 man

enter image description here

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...