[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Simple c program won't compile



* Mark Phillips (mark@infoeng.flinders.edu.au) 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?
> 
> Thanks,
> 
> Mark.

Mark you need to link to math library:

gcc -g thick.c -lm -o thick

And main should be:

int main(int argc, char **argv);


HTH,

Juan Fuentes 



Reply to: