问题如下:
#include <stdio.h>
#include <math.h>
void showerror();
int main()
{
int a;
scanf ("%d",&a);
while (a<0)
{
showerror();
scanf ("%d",&a);
}
printf("sqrt(a)=%.2f\n",sqrt(a));
}
void showerror()
{
printf("input error!\n");
}
使用vscode连接fedora使用gcc进行编译,因为使用了sqrt()函数,所以引用了math.h头文件,在编译的时候报错如下:
/usr/bin/ld: /tmp/cc7BkHGC.o: in function main': 8-1.c:(.text+0x5d): undefined reference to
sqrt’
尝试在编译指令中加入-lm解决,失败;
解决方案:换用g++进行编译即可