You are not logged in.
Pages: 1
I wrote a program that uses sqrt function from math.h header file
here's the source code
//sqrtchk.c
#include<stdio.h>
#include<math.h>
int main()
{
int a;
double b;
puts("Enter a number that is greater than 0:");
scanf("%d",&a);
b=sqrt((double)a);
printf("Square Root is %lf",b);
return(0);
}
i compiled it with this command and got this error
[mcool@ArchLinux tests]$ gcc sqrtchk.c -o sqrt
/tmp/ccagMCOp.o: In function `main':
sqrtchk.c:(.text+0x30): undefined reference to `sqrt'
collect2: error: ld returned 1 exit status
what should i do?
Last edited by mcool4151 (2013-05-19 12:50:11)
Offline
You need to link to libm. Add "-lm" to your options.
Offline
Thanks.......
Offline
Welcome to the forums mcool4151.
Moving from Applications & Desktop Environments to Programming & Scripting.
aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies
Offline
Pages: 1