sinf compiler error I don't understand FIXED!!

Ian Malone ibmalone at gmail.com
Mon Apr 4 06:57:59 UTC 2011


On 3 April 2011 23:25, les <hlhowell at pacbell.net> wrote:
> On Sun, 2011-04-03 at 00:13 +0100, Ian Malone wrote:
>> On 1 April 2011 23:29, les <hlhowell at pacbell.net> wrote:

>> > Clearly sinf is recognized, and compiles and runs.  It returns 1.000 as
>> > expected for M_PI/2.  But the line that is commented out will not
>> > compile.

> The first response found the error -lm which fired up the linker with
> the module.  Apparently the compiler auto replaced sinf(M_PI/2) with a
> constant and didn't throw the linker error, where as the second one put
> in the call to the math library and threw the error.  Adding -lm loads
> the library.
>
>        I was compiling as C, but thought the error might have come due to my
> miscalling gcc thus invoking the C++ compiler and missing something to
> call the correct sin function i.e. sin/sinf/sinl etc.  But I had written
> good code, just misinterpreted the error and forgot the link argument.
> I guess the C++ form as you used probably seeks to find any libraries
> required by the code, preventing linker errors.  That is probably a good
> thing.
>

An old favourite, I must have misread your post, because if I'd
thought you were compiling as C not C++ that would have been the first
thing to come to mind. libm is not linked in C unless explicitly
specified, but is always included in C++: difference in the languages.
The part where it replaces the call to sinf with a constant and masks
the error is particularly devious.

I think there have been suggestions that it's time to start having
libm linked in gcc by default as the space saving (its purpose a very
long time ago) is tiny.

-- 
imalone


More information about the users mailing list