Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Undefined reference to pow

Reply
Thread Tools

Undefined reference to pow

 
 
Trespasser
Guest
Posts: n/a
 
      09-21-2007
I'm embarrassed. I can't make this go:

#include <math.h>

main(int argc, char ** argv)
{
double result;

result = pow(2.0, 3);

}

I get undefined reference to pow.

Any clues?


 
Reply With Quote
 
 
 
 
Neelesh Bodas
Guest
Posts: n/a
 
      09-21-2007
On Sep 21, 11:45 am, "Trespasser" <NOSPAM@NOSPAM> wrote:
> I'm embarrassed. I can't make this go:
>
> #include <math.h>

prefer #include <cmath> instead of <math.h>

>
> main(int argc, char ** argv)

missing return type
> {
> double result;
>
> result = pow(2.0, 3);
>
> }
>
> I get undefined reference to pow.
>

Thats a linker error, not a compilation error. Are you linking the
appropriate libraries?

-N

 
Reply With Quote
 
 
 
 
Trespasser
Guest
Posts: n/a
 
      09-21-2007
"Neelesh Bodas" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> On Sep 21, 11:45 am, "Trespasser" <NOSPAM@NOSPAM> wrote:


> Thats a linker error, not a compilation error. Are you linking the
> appropriate libraries?
>
> -N
>


Thanks Neelesh for the very quick reply.

Ah, I understand. I need to maybe link in a a mathematics library module
when I compile with GCC. If that's not exactly it, then I think I'm back on
track a bit. Thanks.


 
Reply With Quote
 
Trespasser
Guest
Posts: n/a
 
      09-21-2007
Yep. 'GCC -lm source.c' fixed it!

Thanks again.

"Trespasser" <NOSPAM@NOSPAM> wrote in message
news:46f36c81$0$28209$(E-Mail Removed)...

> Thanks Neelesh for the very quick reply.
>
> Ah, I understand. I need to maybe link in a a mathematics library module
> when I compile with GCC. If that's not exactly it, then I think I'm back
> on track a bit. Thanks.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
typeof x == 'undefined' or x == undefined? -Lost Javascript 13 01-31-2007 12:04 AM
undefined vs. undefined (was: new Array() vs []) VK Javascript 45 09-12-2006 05:26 PM
pow(2, 1/2) != pow(2, 0.5) problem Michel Rouzic C Programming 52 06-20-2005 10:24 PM
undefined behavior or not undefined behavior? That is the question Mantorok Redgormor C Programming 70 02-17-2004 02:46 PM
math.pow vs pow Clueless Moron Python 5 11-28-2003 09:56 PM



Advertisments