fmod ?

hello ?

gcc fmodtest.c

i got :
/tmp/cclMGDI0.o: In function main': /tmp/cclMGDI0.o(.text+0x24): undefined reference to fmod’
/tmp/cclMGDI0.o(.text+0x5c): undefined reference to fmod' /tmp/cclMGDI0.o(.text+0x94): undefined reference to fmod’
/tmp/cclMGDI0.o(.text+0xcc): undefined reference to `fmod’
collect2: ld returned 1 exit status

the fmodtest.c is :

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

int main( void )
{
printf( “%f\n”, fmod( 4.5, 2.0 ) );
printf( “%f\n”, fmod( -4.5, 2.0 ) );
printf( “%f\n”, fmod( 4.5, -2.0 ) );
printf( “%f\n”, fmod( -4.5, -2.0 ) );

return EXIT_SUCCESS;

}

the “math.h” have alread been included ,why still is there this erro? and i have found “math.h” in /usr/include director , what can i do ?
thanks !

If you are compiling a C program for QNX, I recommend you to use better qcc.
You are missing the math functions library, you have to include it
(libm.so.___)

With qcc is (example):
qcc fmodtest.c -l /lib/libm.so.2

I think with gcc you need -s or -shared, try with:
gcc fmodtest.c -shared /lib/libm.so.2

But with gcc I am not sure. With qcc and including the library file, your program must work.

I hope it helps

Actually you want to do this…

qcc -o fmodtest fmodtest.c -lm

Thanks , it’s ok now ! :slight_smile: