Undefined reference to pow

Discussion in 'C++' started by Trespasser, Sep 21, 2007.

  1. Trespasser

    Trespasser Guest

    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?
     
    Trespasser, Sep 21, 2007
    #1
    1. Advertising

  2. 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
     
    Neelesh Bodas, Sep 21, 2007
    #2
    1. Advertising

  3. Trespasser

    Trespasser Guest

    "Neelesh Bodas" <> wrote in message
    news:...
    > 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.
     
    Trespasser, Sep 21, 2007
    #3
  4. Trespasser

    Trespasser Guest

    Yep. 'GCC -lm source.c' fixed it!

    Thanks again.

    "Trespasser" <NOSPAM@NOSPAM> wrote in message
    news:46f36c81$0$28209$...

    > 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.
    >
     
    Trespasser, Sep 21, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael B. Williams

    Math.pow Question

    Michael B. Williams, May 29, 2004, in forum: Java
    Replies:
    3
    Views:
    4,870
    Chris Smith
    May 29, 2004
  2. Michael B. Williams

    (re;) Math.pow Question

    Michael B. Williams, May 30, 2004, in forum: Java
    Replies:
    1
    Views:
    402
    Sudsy
    May 30, 2004
  3. Michael B. Williams

    for Mr Andrew Thompson re: Math.pow Question

    Michael B. Williams, May 30, 2004, in forum: Java
    Replies:
    1
    Views:
    357
    Andrew Thompson
    May 30, 2004
  4. Clueless Moron

    math.pow vs pow

    Clueless Moron, Nov 27, 2003, in forum: Python
    Replies:
    5
    Views:
    964
    John J. Lee
    Nov 28, 2003
  5. Michel Rouzic

    pow(2, 1/2) != pow(2, 0.5) problem

    Michel Rouzic, Jun 15, 2005, in forum: C Programming
    Replies:
    52
    Views:
    1,739
    Alan Balmer
    Jun 20, 2005
Loading...

Share This Page