[ale] Missing "floor"?
leam hall
leamhall at gmail.com
Wed Jun 19 12:46:15 EDT 2013
Ed, thanks!
Oddness, the RHEL 5 box I'm on needs the -lm option. Of course, it would be
nice for them to pick options that are easy to tell if they are numbers or
characters. :(
Leam
On Wed, Jun 19, 2013 at 12:02 PM, Ed Cashin <ecashin at noserose.net> wrote:
> Yes, ignoring stuff like inline functions defined in headers, standard
> UNIX-like expectations would be for the header math.h to contain a function
> *prototype* that *declares* floor.
>
> The library contains the compiled floor function *definition* as
> executable code for your architecture. The source for the definition is
> part of glibc, probably a function body *defined* in a .c file.
>
> Both the source and the compiled form of the function can be thought of as
> the implementation in different forms. The declaration in the header is
> information that the compiler can use to make sure that the types of the
> function parameters and of the return value are right. You can think of
> the header stuff as "interface" as opposed to "implementation", but the C
> language and runtime aren't essentially modular, so you'll exhaust the
> usefulness of that metaphor if you go very deep.
>
> Usually the specific difference is the compiler option Sparr mentions.
> You can see that on the CentOS 6 system I'm using, the option isn't
> required:
>
> [ecashin at marino ~]$ cat > t.c
> #include <math.h>
> #include <stdio.h>
>
> int main(void)
> {
> printf("%g\n", floor(2.3));
> return 0;
> }
> [ecashin at marino ~]$ gcc -Wall t.c
> [ecashin at marino ~]$ ./a.out
> 2
> [ecashin at marino ~]$ gcc -Wall t.c -lm
> [ecashin at marino ~]$ ./a.out
> 2
> [ecashin at marino ~]$
>
>
> On Wed, Jun 19, 2013 at 10:54 AM, Sparr <sparr0 at gmail.com> wrote:
>
>> math.h only declares the function. The implementation is in /var/lib/libm
>> (math lib). You need to tell the compiler to link to that with -lm
>> On Jun 19, 2013 10:52 AM, "leam hall" <leamhall at gmail.com> wrote:
>>
>>> Morning Ed!
>>>
>>> I'm looking around (googling) to understand what you mean and I'm not
>>> getting it. math.h is included in the program and exists in /usr/include.
>>>
>>> Leam
>>>
>>>
>>>
>>> On Wed, Jun 19, 2013 at 10:30 AM, Ed Cashin <ecashin at noserose.net>wrote:
>>>
>>>> Maybe link the math library? A quick check suggests that's it.
>>>>
>>>> [ecashin at marino ~]$ man floor | grep Link
>>>> Link with -lm.
>>>> [ecashin at marino ~]$
>>>>
>>>> On Wed, Jun 19, 2013 at 10:18 AM, leam hall <leamhall at gmail.com>wrote:
>>>>
>>>>> Not sure why I'm getting:
>>>>>
>>>>> gcc -Wall -Werror -o rand rand.c
>>>>> /tmp/ccAJ7e8S.o: In function `main':
>>>>> rand.c:(.text+0x16): undefined reference to `floor'
>>>>> collect2: ld returned 1 exit status
>>>>>
>>>>> ###
>>>>> rand.c
>>>>> ###
>>>>>
>>>>> #include <stdio.h>
>>>>> #include <unistd.h>
>>>>> #include <stdlib.h>
>>>>> #include <math.h>
>>>>>
>>>>> int main(void) {
>>>>>
>>>>> int num;
>>>>> float val = 2.3;
>>>>> num = floor(val);
>>>>> printf("num is %d.\n", num);
>>>>>
>>>>> return 0;
>>>>> }
>>>>>
>>>>> --
>>>>> Mind on a Mission <http://leamhall.blogspot.com/>
>>>>>
>>>>> _______________________________________________
>>>>> Ale mailing list
>>>>> Ale at ale.org
>>>>> http://mail.ale.org/mailman/listinfo/ale
>>>>> See JOBS, ANNOUNCE and SCHOOLS lists at
>>>>> http://mail.ale.org/mailman/listinfo
>>>>>
>>>>>
>>>>
>>>
>>> --
>>> Mind on a Mission <http://leamhall.blogspot.com/>
>>>
>>> _______________________________________________
>>> Ale mailing list
>>> Ale at ale.org
>>> http://mail.ale.org/mailman/listinfo/ale
>>> See JOBS, ANNOUNCE and SCHOOLS lists at
>>> http://mail.ale.org/mailman/listinfo
>>>
>>>
>> _______________________________________________
>> Ale mailing list
>> Ale at ale.org
>> http://mail.ale.org/mailman/listinfo/ale
>> See JOBS, ANNOUNCE and SCHOOLS lists at
>> http://mail.ale.org/mailman/listinfo
>>
>>
>
>
> --
> Ed Cashin <ecashin at noserose.net>
> http://noserose.net/e/
> http://www.coraid.com/
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo
>
>
--
Mind on a Mission <http://leamhall.blogspot.com/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.ale.org/pipermail/ale/attachments/20130619/f4237b83/attachment-0001.html>
More information about the Ale
mailing list