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: Matt Adams <stormkeeper at softhome dot net>
- Subject: Re: Undefined references when using math.h
- From: Andreas Jaeger <aj at suse dot de>
- Date: 02 Mar 2000 08:31:34 +0100
- Cc: glibc-linux at ricardo dot ecn dot wfu dot edu
- References: <00030203024504.19297@zaphrod>
- Reply-To: glibc-linux at ricardo dot ecn dot wfu dot edu
>>>>> Matt Adams writes:
> 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?
You night to link against the math library with -lm, e.g.:
cc -o foo foo.c -lm
Andreas
--
Andreas Jaeger
SuSE Labs aj@suse.de
private aj@arthur.rhein-neckar.de