[OCLUG-devel] math functions in C

Bao C. Ha bao at hacom.net
Tue Nov 9 23:12:53 PST 2004


gcc -o prog prog.c -lm

You need "-lm" to link to the math library.

Bao

On Tue, November 9, 2004 11:38 pm, Thomas Moore said:
> Hi all,
>
> I have only been on this list for a short time but
> have never seen a posting. But I will anyway. I am
> not a programmer but do write small programs for
> my amusement.
>
> Here is a short C program to illustrate my
> problem:
>
>
>
> #include <stdio.h>
> #include <math.h>
>
> int main(void)
> {
>  double x = .7854;
>  double y;
>
>  y = sin(x);
>  printf("sin(%f) = %f\n\n", x, y);
> }
>
> Then doing
>
> gcc -o prog prog.c
>
> I get the following message:
>
>
> /tmp/ccZW5o7k.o(.text+0x1a): In function `main':
> : undefined reference to `sin'
> collect2: ld returned 1 exit status
>
>
> Now, math.h refers to mathcall.h which contains
> all the function prototypes. Why will this not
> compile? Or more to the point, what am I doing
> wrong?
>
> Thanks.
>
> Tom
>
>
> _______________________________________________
> OCLUG-devel mailing list -- OCLUG-devel at oclug.org
> http://mailman.oclug.org/mailman/listinfo/oclug-devel
>


-- 
Best Regards.
Bao C. Ha
Hacom OpenBrick Distributor USA http://www.hacom.net
voice: (714) 530-8817 fax: (714) 530-8818
8D66 6672 7A9B 6879 85CD 42E0 9F6C 7908 ED95 6B38




More information about the OCLUG-devel mailing list