Why are my math functions not being included?
I am using RedHat Linux 7.2 and am working my way through Beginning Linux Programming,3rd ed. I've been encountering errors when attempting to compile program 'limits.c' (pp 1678). The math function 'log' is not being recognized.
I've tried this out with some of the other math functions which should have been included with 'math.h', and they are missing as well. To demonstrate, suppose I try to compile this simple program:
#include <math.h>
#include <stdio.h>
int main()
{
double x = 4.5;
double y;
y = sqrt(x);
printf("Square root of %.1f is %.3f\n", x, y);
y = log(x);
printf("Natural log of %.1f is %.3f\n", x, y);
y = exp(x);
printf("e raised to power %.1f is %.3f\n", x, y);
exit(0);
}
Compilation fails with the following error message (/tmp info omitted):
In function `main':
undefined reference to `sqrt'
undefined reference to `log'
undefined reference to `exp'
It appears that NONE of the functions which should have been included with 'include <math.h>' were actually included.
I tried this same program on my Mac OS X/Darwin, and the program compiled and ran correctly.
Can anyone tell me why the math.h library is not being included on my Linux installation?
Jim Keenan
Just Another Perl Hacker
