C Library reference error using sqrt() - will not compile.

This so basic that it should work.... Any ideas would be appreciared. Using a number directly in the sqrt allows it to compile.

primrose > cat a.c
 
#include <stdio.h>
#include <math.h>
int main(void)
{
double abcd=9;
printf("%f\n",sqrt(abcd));
}
 
primrose > gcc a.c
Undefined first referenced
symbol in file
sqrt /var/tmp//ccm7jh8O.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
 
primrose >
gcc a.c -lm

link in the math library

1 Like

Thanks, its been seven years since I last used C. I will sudy the gcc command and hopefully not need to ask rooky questions again.
Your answer was spot on.