pow() isn't defined [closed]

#include <stdio.h>
#include <math.h>

void main()
{
    int i, diff, sum = 0, num1 = 6, num2 = 2;

    for(i = 0; i <= 4; i++)
    {
        diff = num1 - num2;
        sum += pow(diff, i);
    }

    printf("%d", sum);
}

Whenever I am trying to execute this program, an error message just pops up saying:

In function main:
undefined reference to pow.

What am I missing here?


This is a linker failure. You need to link with the math library, specify -lm at the end of your compiler command. From man pow:

Link with -lm.


Math library is not part of libc. You need to link it:

gcc file.c -lm -o file