The following program, "main_good.c",
Code:
#include <stdio.h>
#include <math.h>

int main ()
{
        double p = 3.14159265;
//        double s = sin(p/4.0);
        double s= sin(3.14159265/4.0);
        printf ("sin  is %f\n", s);
}
compiles under gcc without problems (and produces the correct answer).

But the following code, "main_bad.c",
Code:
#include <stdio.h>
#include <math.h>

int main ()
{
        double p = 3.14159265;
        double s = sin(p/4.0);
//        double s= sin(3.14159265/4.0);
        printf ("sin  is %f\n", s);
}
Produces rhw error:
Code:
/tmp/cc819Wha.o: In function `main':
main_bad.c:(.text+0x23): undefined reference to `sin'
collect2: ld returned 1 exit status
Following a suggestion in this thread , tried compiling with the -lm switch. Same error.

Can anyone explian what is happening ?
Hopefullly something simple; haven't programmed in plain old C for a long time.
thanks for any help -