This is the mail archive of the glibc-linux@ricardo.ecn.wfu.edu mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Undefined references when using math.h


>>>>> 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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]