This is the mail archive of the
glibc-linux@ricardo.ecn.wfu.edu
mailing list for the glibc project.
Re: Undefined references when using math.h
- To: glibc-linux at ricardo dot ecn dot wfu dot edu
- Subject: Re: Undefined references when using math.h
- From: "tjk at tksoft dot com" <tjk at tksoft dot com>
- Date: Thu, 2 Mar 2000 06:02:42 -0800 (PST)
- Reply-To: glibc-linux at ricardo dot ecn dot wfu dot edu
You have to link with the math library.
(libm.so, libm.a, aka -lm)
E.g.
"cc -o foo foo.c -lm"
Troy
Troy Korjuslommi Tksoft OY, Inc.
tjk@tksoft.com Open Source Solutions
Linux Technical Support
>
> Hi there,
>
> My apologies if this is off-topic. I kept receiving majordomo errors
> when I sent it to linux-c-programming.
>
> I've found something rather unsettling when trying to use a
> function from math.h
>
> ---example code---
>
> #include <stdio.h>
> #include <math.h>
>
> main()
> {
> double x = 1.0;
> double ans;
>
> ans = sqrt(x);
>
> printf("\nans is %lf\n", ans);
>
> return 0;
> }
>
> ---end example code---
>
> When I attempt to run "cc -o foo foo.c" I get this error:
>
> /tmp/cczmmVQB.o: In function `main':
> /tmp/cczmmVQB.o(.text+0x409): undefined reference to `sqrt'
> collect2: ld returned 1 exit status
>
> which is rather annoying <g> How might this be fixed?
>
>
> I would appreciate any suggestions or comments.
>
> Thanks -- Matt
>
> BTW, I'm using gcc, egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
> Slackware 7.0, i586
>
>