Undefined reference to `pow’ when compiling C program

Published on December 23, 2016 by abundantcode

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: 0 (0 votes)

This article have been viewed 3266 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


x

You might be Interested in these Posts

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...

C# Program to find the ASCII Value of a Character

Problem Write a program in Visual C# to find the ASCII value of the input character. How to find t...