[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [MiNT] Gcc 4.4.3 Linking problems, libmath testcase attached...



Miro Kropacek a écrit :
Btw, this is not entirely true for C++ code, at least in your newer
builds -- for example cmath header defines ceilf as alias to built-in
ceilf function so no -lm is needed for m0n0's example code.

If -lm was not needed, why do we get undefined references ??

If I'm not wrong, it is the same for C and C++.
By default, for well-known functions, gcc uses its own built-in functions instead of generating function calls, except when -fno-builtin is specified. The built-in functions are either replaced by the obvious result if it can be computed at compile time, or by a function call to the real function when it is not possible.

When making tests be sure to use global variables as arguments, because if you use constants GCC will replace the whole expression by the computed result !

The attached program is a good testcase, I would be surprised if anyone could compile it without -lm. You can even replace the call to ceil() by __builtin_ceil() to force the usage of the builtin "function", it will be the same.

--
Vincent Rivière
#include <math.h>

double a = 123.4f;
double b;

int main(void)
{
    b = ceil(a);

    return 0;
}