Results 1 to 7 of 7

Thread: pow

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Posts
    118

    pow

    Hi,

    The following is my code. When I tried to compile it. It give me an error massage "undefined reference to 'pow'. I thought I did include #include <math.h>....

    Any idea?
    Thanks.


    #include <stdio.h>
    #include <conio.h>
    #include <math.h>

    void main(){
    int i;
    float s, l;
    printf("\n\t|----------------------------------------------------|");
    printf("\n\t| x | x^2 | cube root of x | x^4 |");
    printf("\n\t|----------------------------------------------------|");
    for (i=1;i<=100;i++)
    {
    s = i*i;
    l = s*s;
    printf("\n\t| %d |",i);
    printf(" %5.0f |",s);
    printf(" %5.3f |",pow(i,1.0/3.0));
    printf(" %5.0f |",l);
    printf("\n");
    getch();
    }
    printf("\t|-----------------------------------------------------|");
    getch();
    }

  2. #2
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: pow

    As far as I remember, pow() returns a double value, so instead of %f use %lf.
    Show Appreciation. Rate Posts.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Posts
    118

    Re: pow

    still...

    /tmp//ccg24629.o: In function `main':
    /tmp//ccg24629.o(.text+0xaf): undefined reference to `pow'
    collect2: ld returned 1 exit status

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: pow

    You need to link against the math library, libm. Add -lm to the compiler command line.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Posts
    118

    Re: pow

    like this #include <libm.h>?

    I though this #include <math.h> should do it.

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: pow

    No, not like this. You need to learn the difference between a library file and a header file. I explicitly said 'command line', too, and what you must put there.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Posts
    118

    Re: pow

    oh ok..got it

    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width