I found a very strange thing. When I use the log function in the math.h
library, I cannot use variables.
#include<stdio.h>
#include<math.h>
int main(){
int b=100;
double a = log10(100)/log10(10);
printf("%lf",a);
return 0;
}
The above code works fine. But the following code reports an error.
#include<stdio.h>
#include<math.h>
int main(){
double b=100;
double a = log10(b)/log10(10);//Just change 100 to variable b
printf("%lf",a);
return 0;
}
The error is
/usr/local/bin/ld: /tmp/cc8j9x4e.o: in function `main':
ctest.c:(.text+0x19): undefined reference to `log10'
collect2: error: ld returned 1 exit status