Re: Simple c program won't compile
Mark Phillips wrote:
>Hi,
>
>The following program:
>
>
>#include <stdio.h>
>#include <math.h>
>
>int main(int argv, char **argc){
> double x;
>
> x=sqrt(5.0);
>}
>
>
>does not compile. Instead I get the errors:
>
>$ gcc thick.c
>/tmp/ccU9fgSr.o: In function `main':
>/tmp/ccU9fgSr.o(.text+0x16): undefined reference to `sqrt'
>collect2: ld returned 1 exit status
>
>
>What is wrong?
Your problem is in the link stage. sqrt() is part of the maths library and
so you need to add -lm to your compilation options.
--
Oliver Elphick Oliver.Elphick@lfix.co.uk
Isle of Wight http://www.lfix.co.uk/oliver
PGP: 1024R/32B8FAA1: 97 EA 1D 47 72 3F 28 47 6B 7E 39 CC 56 E4 C1 47
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
========================================
"This is the day which the LORD hath made; we will
rejoice and be glad in it." Psalms 118:24
Reply to: