Beginner C/C++

Moderators: None (Apply to moderate this forum)
Number of threads: 5430
Number of posts: 16951

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
sqrt() in math.h Posted by Gregry2 on 18 Jul 2010 at 7:14 PM
Hey guys, It's been a million years since I touched here. I'm 20 now, and I kind of want to go back to what I used to do for fun when I was 15 or so.

Anyway, I have a very simple problem, even though I include math.h, I get an "undefined reference to "sqrt" error. I really am lost. Looking at math.h in /usr/include looks fine...of course. Any ideas? I'm not misspelling it or anything...

thanks
{2}rIng
Report
Re: sqrt() in math.h Posted by AsmGuru62 on 18 Jul 2010 at 8:28 PM
Can you post the full error message? Try to create a simple project, like:
#include <math.h>

int main ()
{
    double a = 5.9348873;
    double b = sqrt (a);
    return 0;
}

That also does not work? If that works, then some additional code is affecting your project, like some obscure defines hidden in other .H files or something of that kind. MFC likes to do it a lot - with some defines from stdafx.h it excludes some functions included into WINDOWS.H file.

Is the sqrt error the first one in a list of errors? If not - begin from the first one - in most cases a first error in C causes the rest of errors.
Report
Re: sqrt() in math.h Posted by Gregry2 on 31 Jul 2010 at 8:47 PM
I just forgot to link the math library...sorry.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.