PDA

View Full Version : gcc: undefined reference to `sqrt' even if I included math.h



martin8411
07-11-2011, 11:58 PM
So I have this C code:



#include<stdio.h>
#include<stdlib.h>
#include<math.h>

double dist(int x*, int y*, int x2, int y2){
double dx = (double) (x* - x2);
double dy = (double) (y* - y2);
double xx = pow(dx, 2.0);
double yy = pow(dy, 2.0);
double distance = sqrt(xx + yy);
return distance;
}

But gcc complains that:




/tmp/cck84m*o.o: In function `dist':
astar.c:(.text+0x5d): undefined reference to `sqrt'
collect2: ld returned * exit status

I don't get why gcc would say that. Anything I missed?