Ryan Rampersad
Thoughts, opinions, ideas and now links
  • About
  • Podcast
  • Links

C: undefined reference to `pow’

December 12, 2011

I was helping a friend with a little C-program recently. C is not my language of choice, and when I was tinkering years ago, I was using a Windows compiler and not gcc. Things are a little different in the Ubuntu compilation world. I was receiving an unexpected error message even though I had proper headers.

testing.c:(.text+0×156): undefined reference to `pow’
testing.c:(.text+0×174): undefined reference to `pow’
testing.c:(.text+0x18e): undefined reference to `pow’

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

My code was modestly simple. The variables were previously defined and perfectly in order.

      double left = a * pow(b, 3);
      double right = pow(c, 2) - pow(d, e);

Apparently, in order to make gcc load the proper library, you need to explicitly tell it to in the call to compilation. gcc -lm testing.c -o math && ./testing

Notice the -lm flag? That tells gcc to load a specific library, and in this case, the math library.

Tagged: C, coding, error, Tips
<Previous Next>

© 2013 Ryan Rampersad.