I just bought a Gert board and downloaded some utilities off the net. They were written in C and I compiled them as directed. All is working well.
I must admit that I was surprised that the Raspberry Pi had a C compiler on board. Now I've been using Python and really enjoying it but back
in the day I used to write a lot of C programs. So I had to start playing around. After the obligatory "Hello world!" program, I started working on
another of my favorites: a program that calculates the monthly payment of a loan. This program uses the pow() function and I'm having some
problems.
Basically, pow() works if I use literals as arguments but won't compile otherwise. The following compiles fine:
#include <math.h>
main() {
double result;
result = pow(2.0, 0.5);
printf("%f\n", result);
}
It compiles fine and the square root of 2 is returned when run. But if I try:
#include <math.h>
main() {
double result, i, j;
i = 2.0; j = 0.5;
result = pow(i, j);
printf("%f\n", result);
}
I get the following compiler error:
cc -o loan loan.c
/temp/ccFPrtMo.o: in function 'main';
loan.c:(.text+0x11c): undefined reference to 'pow'
collect2: ld returned 1 exit status
Any ideas? Thanks, Mark