Okay, we've coded a simple C program like this using the pow() function to elaborate our problem here:
Code:
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
printf("TEST: %d\n", pow(2, 3));
return 0;
}
Seems like the program should work, right?
When we try to compile it, we get
In function `main':
/home/shared/dev/plugin-sdk/test.c:7: undefined reference to `pow'
collect2: ld returned 1 exit status
Now, if we take POW out of our program like this
Code:
int main(int argc, char *argv[])
{
printf("TEST: %d\n", 0); //pow(2, 3));
return 0;
}
Compile this above code, and run it we get
TEST: 0
In other words, the program works and executes correctly if we take out all traces of the pow() function.
This would suggest that our copy GCC doesn't have support for the function pow();. After all, it does say undefined reference, meaning, "Hey! I dont know what this function is!"
This would indicate that gcc was put on our server without pow() support. In order to get pow() functions going, it appears the only way is going to be to install the newest version of gcc.
We need to have power functions unless we plan to code the functions ourself.
So, I'm getting at is:
1) Will re-installing GCC be too much of a dangerous task to do on the server to try and upgrade?
2) If so, how should we go about getting pow() to work?
3) Am I correct about it being GCC's fault for not compiling the pow function or are we actually using or declaring pow wrong?
Is this going above everyones head or is
anyone still with me here? ;-)
If I can't get any responses here I figure I'll give it a try over at the Programmers section of LQ too.
UPDATE:
Problem solved!
We were doing the following which is
WRONG:
printf("TEST: %d\n", pow(2, 3));
The correct way would be to use:
printf("TEST: %lf\n", pow(2, 3));
Another thing is you have to pass the -lm option to gcc to make it do the math functions. E.G. gcc -g -O2 -lm test.c -o test
Thanks for the help everyone, I hope when this gets to the 'time based archive' it can help someone else too. ;- )