0

I have included the math.h header file.

If I do something like

   float var = pow(2, 3)  

it complies and there aren't any errors. But if I try something like

float var2 = 5;
float var = pow(var2, 2)

it doesn't compile and gives me the error

undefined reference to `pow' collect2: error: ld returned 1 exit status

I am not very familiar with c, but I have no idea why this is happening, as it is fine without using a variable. It's like if I use a variable in the pow function, it gives me this error. I am using Xubuntu and then run the command

"cc -g -std=c99 myfile.c 

to compile the program.

  • compile with the flag `-lm` like this:gcc yours.c -lm -o yours – Behnam Safari Feb 09 '14 at 11:40
  • 3
    @mb84 Totally wrong and unhelpful. Did you even read the question? do you understand what happens to an `int` when passed to a function expecting a `float`? –  Feb 09 '14 at 11:43
  • @H2CO3 I know. I just confound it with unresolved overload, but its not the case, you are right. – mb84 Feb 09 '14 at 11:50

1 Answers1

2

To link in the math library, which you need for the pow() function, compile with this switch added:

gcc -g -std=c99 myfile.c -lm
Martin Dinov
  • 8,757
  • 3
  • 29
  • 41