2

Screen shot of the build log

It seems that it is not able to locate math library. While compiling this program gives an error:

undefined reference to'pow'

I am completely clueless about this.

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

int main() {
    int number1, temp, number2 = 0, x, count = 0;
    printf ("Enter number: ");
    scanf("%d", &number1);

    x = number1;
    while (number1 > 0)
    {
        temp = number1 % 10;
        number2 = (number2 + temp)*pow(10, count++);
        number1 = number1/10;
    }

    printf("The original number order was: %d\n", x);
    printf("\n");

    printf("The reverse number order is: %d\n", number2);
    return 0;
}
the busybee
  • 10,755
  • 3
  • 13
  • 30
M K Sundaram
  • 49
  • 1
  • 7

3 Answers3

4

You add "libm.a" to your "Link libraries" if you're using the GNU GCC Compiler in a Debian based Linux environment.

  1. Click on "Project"
  2. Click "Build options.."
  3. Click the "Linker settings" tab
  4. Click the "Add" button inder the "Link libraries"
  5. Type in "libm.a" and click "OK"
  6. Click "OK" again (this time on the "Project build options" window)

And make sure you have #include <math.h>

SunnyDaze
  • 141
  • 3
3

You need to link math library while compiling your program like this:

gcc test.c -lm

Here is a good explanation why is it necessary for <math.h>.

Sam______
  • 114
  • 7
0

Another way is:

  1. Click on "Settings",
  2. Click on "Compiler",
  3. Click on "Linker settings" tab,
  4. Click on "Add",
  5. Type "libm.a" and "OK",
  6. Click on "OK" and that's all.

You're ready lo link against math library on linux using gcc (Don't forget "#include <math.h>" in your source code).

Ernesto
  • 19
  • 2