Problem with Pow() function

Asked

Viewed 1,970 times

3

Would someone tell me why the following code does not compile?

#include <math.h>

double f(double x){
      return (x - (pow(2,x)));
}
  • 1

    Which error?

  • undefined reference to `Pow'

  • How is the code running? How was it compiled ? If it was through an IDE, what was it ? If it was compiled by hand, include the command you used

  • This is a link error, I imagine, due to the message. It’s not build. Try compiling with the option -c if using GCC (I believe ICC also follow the same flags)

1 answer

5


Compile, compile. But not linka because the mathematical library was not added to the build of executable.

The library referenced by the header math.h is not linked by default like other basics, because it can change according to the platform, and you have to say that you want it to be used in the process of build, then put this in the compiler command line:

-lm

Browser other questions tagged

You are not signed in. Login or sign up in order to post.