Page 1 of 1

problem with gcc compiler and math functions

Posted: Thu 04 Oct 2012, 16:59
by gemera
I've compiled tons of c programs in Puppy using Geany and the gcc compiler without any problems.

But for the first time I have used one of the math functions defined in the <math.h> header and get an error which I just can't solve.

Since I am learning c for both Windows and Linux I know the program works in the gcc compiler in Codeblocks for Windows.

Code: Select all


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

int main(void)
{
      double x,y;

      x = 5;

      y = sqrt(x);

      return 0;
}

the error message is

Code: Select all


/tmp/ccr0Yo3k.o: In function `main':
/root/test.c:11:undefined reference to `sqrt'
collect2: ld returned 1 exit status
make: ***[all] Error 1

btw I can use ANY of the math functions and get the same error.

Posted: Thu 04 Oct 2012, 17:41
by SFR
Hey Gemera

Although I don't know C at all (high time to learn it at last...), but I think this will shed some light on the problem:
https://bbs.archlinux.org/viewtopic.php?id=47461

I've compiled your example with -lm and it seems to be ok...

Greetings!

Posted: Thu 04 Oct 2012, 18:13
by gemera
thanks for the heads up sdk.

really appreciated!

Posted: Thu 04 Oct 2012, 21:52
by Karl Godt
This is with newer gcc i think . Had similar on Puppy Precise .