“对‘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) 中运行。但它给出了一条错误消息。
味精- 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