LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Mandriva (https://www.linuxquestions.org/questions/mandriva-30/)
-   -   #include <math.h> does not work (https://www.linuxquestions.org/questions/mandriva-30/include-math-h-does-not-work-187457/)

enlight1 05-29-2004 06:05 PM

#include <math.h> does not work
 
I just did a clean install of Mandrake 10.0 Official. All works fine except when I go to compile a simple c program including math.h. The compile completes and then I get a ld error:

[jerry@localhost practice]$ gcc divide.c -o divide
/home/jerry/tmp/ccKo59RF.o(.text+0x8c): In function `main':
: undefined reference to `sinf'
collect2: ld returned 1 exit status

I first noticed when trying to compile a simple benchmark program and it would not go. Here is code for divide.c. I am just printing the sine of PI.

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

#define LIMIT 1000
#define PI 3.14159

int
main(void)
{
int i, j, result;
float num;
for(i=0;i<LIMIT;i++) {
for(j=1;j<10;j++) {
printf("%d / %d = %d R %d.\n",i,j, i/j, i%j);
}
}
num=sinf(PI);
printf("Thats all folks!\n");
printf("The sin of 1.5 is: %f\n", num);
return(0);
}

any suggestions anyone?

rkef 05-29-2004 07:06 PM

Try
Code:

[jerry@localhost practice]$ gcc -lm divide.c -o divide
... you need to compile it against the math library :).

enlight1 05-29-2004 07:59 PM

That was it. I have to confess I feel a bit stupido after that one :)


All times are GMT -5. The time now is 01:39 AM.