On 3 April 2011 23:25, les <hlhowell@xxxxxxxxxxx> wrote: > On Sun, 2011-04-03 at 00:13 +0100, Ian Malone wrote: >> On 1 April 2011 23:29, les <hlhowell@xxxxxxxxxxx> 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 -- users mailing list users@xxxxxxxxxxxxxxxxxxxxxxx To unsubscribe or change subscription options: https://admin.fedoraproject.org/mailman/listinfo/users Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines