Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 undefined reference to `sqrt'
Index -> Programming, C -> C Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
DtY




PostPosted: 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?
Sponsor
Sponsor
Sponsor
sponsor
Analysis Mode




PostPosted: 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
DtY




PostPosted: 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
Display posts from previous:   
   Index -> Programming, C -> C Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: