math.h does not seem to work

Hi!

I've been trying to use the example for the exp-function of math.h:

1
2
3
4
5
6
7
8
9
10
11
12
13
/* exp example */
#include <stdio.h>
#include <math.h>

int main ()
{
  double param, result;
  param = 5.0;
  result = exp (param);
  printf ("The exponential value of %lf is %lf.\n", param, result );
  return 0;
}


on three different computers (compiled every time with the command " gcc -o exp exp.c "), and in two instances I always get the error:

1
2
3
/tmp/cc2HG2Tq.o: In function `main':
exp.c:(.text+0x21): undefined reference to `exp'
collect2: ld returned 1 exit status


WTF?
Last edited on
Your compiler installation is broken.
No it isn't. He just didn't link with the math library.

gcc -o exp exp.c -lm

Hope this helps.

[edit] Please use [code] tags.
Last edited on
Thanks!
Topic archived. No new replies allowed.