Undefined reference to `pow’ when compiling C program

Published on December 23, 2016 by admin

Filed under C

Last modified December 23, 2016

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 3 (2 votes)

This article have been viewed 16216 times

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.

Leave a Comment


You might be Interested in these Posts

C Program to convert lower case string to upper case

Problem Statement Write a program in C to convert the given string from lower case to upper case. ...

How to decode a base64 string in C#?

Here's a sample code snippet demonstrating how you can easily decode a base64 encoded string in C#. ...

How to disable editing of items in a combo box in c#?

When working in Win forms using C# and especially when you use the combo box , you would have notice...