pow() refuses to take two variables

This is a discussion on pow() refuses to take two variables within the C Programming forums, part of the General Programming Boards category; It works fine with 1 variable one value. I don't understand why. Code: /tmp/cc4KSEcQ.o: In function `main': test.c:(.text+0x2f): undefined reference ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    182

    pow() refuses to take two variables

    It works fine with 1 variable one value. I don't understand why.

    Code:
    /tmp/cc4KSEcQ.o: In function `main':
    test.c:(.text+0x2f): undefined reference to `pow'
    collect2: ld returned 1 exit status
    Code:
    #include <math.h>
    #include <stdio.h>
    
    int main()
    {
    	int x = 2, y = 3;
    	printf( "%.2f\n", pow( y, x ) );
    	return 0;
    }

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    395
    did you link correctly your binary with the math library (-lm)?

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    182
    No, what does -lm do?

  4. #4
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    478
    You included the math header, which contains all constants and prototypes for the functions, but where do you think the code itself is held?

    The math library is too large to be linked to all programs. You need to use "-lm" which pretty much stands for "link math(library)", and include math.h.
    "What's up, Doc?"
    "'Up' is a relative concept. It has no intrinsic value."

  5. #5
    Registered User
    Join Date
    May 2006
    Posts
    182
    thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. basic question about global variables
    By radeberger in forum C++ Programming
    Replies: 0
    Last Post: 04-06-2009, 12:54 AM
  2. Replies: 15
    Last Post: 09-30-2008, 02:12 AM
  3. <math.h> pow() not taking variables in arguments
    By noobcpp in forum C Programming
    Replies: 3
    Last Post: 08-16-2008, 09:10 AM
  4. esbo's data sharing example
    By esbo in forum C Programming
    Replies: 49
    Last Post: 01-08-2008, 10:07 PM
  5. Global Variables
    By Taka in forum C Programming
    Replies: 34
    Last Post: 11-02-2007, 03:25 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21