Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is 'undefined reference to `pow'' [duplicate]

Tags:

c

I have a codepad .

On line 15 inside a for function

 for(i=2; i<=90; i+=2){
    int j=0+i;
    printf("%i\n",i);
    power=pow(inp,j);
    factor=factorial(i);
    if(i%4==0)fAns += power/factor;
    else fAns -= power/factor;
  }

the line power=pow(inp,j); I added j instead of just using i because it gave me the same error. undefined reference to 'pow'.

If I replace j with 2, then it works just fine but when I use j=i it wont work. Is there a problem with incrementing this line?

I want this to increment and not throw me an error.

like image 595
user1082764 Avatar asked Apr 16 '12 01:04

user1082764


People also ask

What is undefined reference to POW?

Fixing undefined reference to 'pow' in Linux This is a common error while compiling C program in GCC/G++ Linux. This error occurs when you are using pow function to calculate power of a number in your programs.

How do you fix a undefined reference?

The error: undefined reference to function show() has appeared on the terminal shell as predicted. To solve this error, simply open the file and make the name of a function the same in its function definition and function call.

Does POW return a double?

The pow() function returns the value x y x^y xy (x raised to the power y) where x and y are two variables of type double. The return type is double.

Why POW is not working in Ubuntu?

The error is because you are trying to use the (integer) modulo operator % with the return value of pow (which has type double ).


1 Answers

You need to link with the math library. With gcc, this would mean passing -lm during linking.

The reason it doesn't complain when you use 2 as the exponent value is because the compiler is optimizing the pow call out.

like image 68
John Ledbetter Avatar answered Oct 21 '22 13:10

John Ledbetter