Undefined reference to `pow’ when compiling C program

This content was proof-read by Grammarly. You can Try Grammary for FREE

When trying to make a simple program in C and compiling it , there are times when you might get an error that you are missing the pow function when you have used them inspite of including the math.h header file.

The error message looks like this.

undefined reference to ‘pow’ collect2: error: ld returned 1 exit status

How to fix the error undefined reference to ‘pow’ ?

You will have to compile your C program with the flag -lm as shown below assuming your program name is abundantcodesample.c

You need to compile with the flag -lm, like this:

gcc abundantcodesample.c -lm -o abundantcodesample

This will inform the gcc to link your program against the math.lib.

%d bloggers like this: