View Full Version : math.h included, but fmod not available

8th January 2006, 03:51
I wrote a program to test my understanding of fmod:

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

int main(void) {
double a = 259192.42201;
double b = 24.10501259;
printf("%11.10f", fmod(a,b));
but I get the error:

samjnaa@linux:~/bin/learning> gcc fmod.c -o fmod
/tmp/ccK9XIYg.o: In function `main':
fmod.c:(.text+0x49): undefined reference to `fmod'
collect2: ld returned 1 exit status
and sure enough /usr/include/math.h has no reference to fmod -- what is this, GCC libraries are useless? Then how do I implement a modulus function? My GCC version is 4.0.2_20050901-3 and I have cpp, libgcc of same version, glibc 2.3.5-40 etc. Please help. Thanks.

8th January 2006, 06:37
you need to link with the math library libm.a
try gcc -o fmod -lm fmod.c