Monday, July 9, 2018

Have I Really Forgotten C?

#include
#include

int main (argc, char ** argv)
{
    float x,y;
    for (x=-2.25f; x<= 2.25f; x+=.1f)
    {
        y = pow(x, 2)-x);
        printf("%0.2f %0.2f\n", x, y);
     }
}

pow is "undefined reference to 'pow'


I needed -lm on the cc line. Thanks.

6 comments:

  1. Was the space in the include file name "math .h" in your original source? If so, that's your error.

    ReplyDelete
  2. Also, using quotes instead of brackets means it looks in local directory for file instead of the compiler include search path.

    ReplyDelete
  3. Ooh, ooh, I know! (Maybe.)

    Add the '-lm' flag to your cc step to link in the math library.

    Also "#include "

    ReplyDelete
  4. In the text shown, the parenthesis are not balanced where y is evaluated. I see an extra ) before the semicolon at the end of the expression.

    ReplyDelete
  5. Do you have a local math.h file?

    ReplyDelete
  6. These expressions aren't allowed in The New Math. Haven't you heard?

    There's a new law coming soon, which will set Pi=3.0 That'll make everything much simpler, won't it!

    ReplyDelete