
-----------------------------------
DtY
Thu May 07, 2009 8:49 pm

undefined reference to `sqrt'
-----------------------------------
So I wrote a function to calculate the distance between two points (using Pythagorean theorem), but when I compile it tells me undefined reference to `sqrt'

#include 
static unsigned int distanceBetween(unsigned int x,unsigned int y,unsigned int xx,unsigned int yy) {
    double X = x;
    double Y = y;
    double XX = xx;
    double YY = yy;
    double result = 0;
    result = pow( pow(X-XX, 2.0) + pow(Y-YY, 2.0) ,0.5);
    return (int)result;
}
I'm guessing that pow() seeing the power as 1/2 calls sqrt, but why wouldn't sqrt be defined?

-----------------------------------
Analysis Mode
Thu May 07, 2009 9:01 pm

Re: undefined reference to `sqrt'
-----------------------------------
I can't really make heads or tails of what it's saying, but here's a [url=http://cboard.cprogramming.com/c-programming/88943-undefined-reference-sqrt.html]link

-----------------------------------
DtY
Thu May 07, 2009 9:12 pm

RE:undefined reference to `sqrt\'
-----------------------------------
Oh thanks, seems I have to add -lm to the linker command if I want to use the math library.

Thanks
