Computer Science Canada

undefined reference to `sqrt'

Author:  DtY [ Thu May 07, 2009 8:49 pm ]
Post subject:  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'

c:
#include <math.h>
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?

Author:  Analysis Mode [ Thu May 07, 2009 9:01 pm ]
Post subject:  Re: undefined reference to `sqrt'

I can't really make heads or tails of what it's saying, but here's a link

Author:  DtY [ Thu May 07, 2009 9:12 pm ]
Post subject:  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


: