I'm a complete newbie in C for Linux. I have this function (tested on Visual Studio, it works and it's not using any C++ or Windows-only functions) that returns the amount of digits inside an integer number (note the use of log10() from math.h), but it throws me the error "log10() undefined reference, ld returned 1 exit status". I also have this very exact problem on other function (the same program) that uses pow() (A function to convert binary to decimal, that works everywhere but Ubuntu, just the same as this one).
int DigitsInNumber(int Num)
{
int Digit = Num;
if (Digit == 0) /* Log10(0) = Math error */
Digit = 1;
else
{
if (Digit < 0) /* Log10(<Negative number>) = Math error */
Digit = Digit * - 1
else
Digit = (int) log10((double) Digit) + 1; /* Log10(250) + 1 = 3
(250 has 3 digits) */
}
return Digit;
}
This code was created on Eclipse (Ubuntu) and g++ (as recommended by the teacher), I know probably there are "duplicates" but the related questions I've read recommended the same thing: "Include math.h, that's what you need." (I did that the very minute the function came to my mind) and "Use ld" (Where?) that none of those answers said where to type or do with it. What do I do about "ld"? Thank you.