我是刚学编程的,有个问题:
/*----sqrt.c------*/
#include<stdio.h>
#include<math.h>
main()
{
float a,b;
printf("Enter a value for a:\n");
scanf("%f",&a);
b=sqrt(a);
printf("The result is %f.\n",b);
}
[txw@TCL txw]$ cc -o sqrt sqrt.c
/tmp/cc8Z2pIW.o(.text+0x42): In function `main':
: undefined reference to `sqrt'
collect2: ld returned 1 exit status
[code:1]
#include<stdio.h>
#include<math.h>
int main()
{
float a,b;
printf("Enter a value for a:\n");
scanf("%f",&a);
b=sqrt(a);
printf("The result is %f.\n",b);
}
[/code:1]
我在gcc3.1上编译很正常,(main 前加了 int)。
gcc -Wall ??.cc -o ??