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.<div><br></div><div>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.</div>
<div><br></div><div>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.</div>
<div><br></div><div>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:</div><div><br></div><div><div>[ecashin@marino ~]$ cat > t.c</div>
<div>#include <math.h></div><div>#include <stdio.h></div><div><br></div><div>int main(void)</div><div>{</div><div> printf("%g\n", floor(2.3));</div><div> return 0;</div><div>}</div><div>
[ecashin@marino ~]$ gcc -Wall t.c</div><div>[ecashin@marino ~]$ ./a.out </div><div>2</div><div>[ecashin@marino ~]$ gcc -Wall t.c -lm</div><div>[ecashin@marino ~]$ ./a.out </div><div>2</div><div>[ecashin@marino ~]$ </div></div>
<div><br><br><div class="gmail_quote">On Wed, Jun 19, 2013 at 10:54 AM, Sparr <span dir="ltr"><<a href="mailto:sparr0@gmail.com" target="_blank">sparr0@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<p dir="ltr">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 </p><div class="HOEnZb"><div class="h5">
<div class="gmail_quote">On Jun 19, 2013 10:52 AM, "leam hall" <<a href="mailto:leamhall@gmail.com" target="_blank">leamhall@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div>Morning Ed!<br><br>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. <br><br></div>Leam<br><br><div class="gmail_extra">
<br><br><div class="gmail_quote">On Wed, Jun 19, 2013 at 10:30 AM, Ed Cashin <span dir="ltr"><<a href="mailto:ecashin@noserose.net" target="_blank">ecashin@noserose.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Maybe link the math library? A quick check suggests that's it.<div><br></div><div><div>[ecashin@marino ~]$ man floor | grep Link</div><div> Link with -lm.</div><div>[ecashin@marino ~]$ </div><br><div class="gmail_quote">
<div><div>
On Wed, Jun 19, 2013 at 10:18 AM, leam hall <span dir="ltr"><<a href="mailto:leamhall@gmail.com" target="_blank">leamhall@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div>
<div dir="ltr"><div><div>Not sure why I'm getting:<br><br></div>gcc -Wall -Werror -o rand rand.c<br>/tmp/ccAJ7e8S.o: In function `main':<br>rand.c:(.text+0x16): undefined reference to `floor'<br>collect2: ld returned 1 exit status<br>
<br>###<br></div>rand.c<br>###<br clear="all"><div><div><div><br>#include <stdio.h><br>#include <unistd.h><br>#include <stdlib.h><br>#include <math.h><br><br>int main(void) {<br><br> int num;<br>
float val = 2.3;<br> num = floor(val);<br> printf("num is %d.\n", num);<br><br> return 0;<br>}<span><font color="#888888"><br><br>-- <br><div><a href="http://leamhall.blogspot.com/" target="_blank">Mind on a Mission</a></div>
</font></span></div></div></div></div>
<br></div></div>_______________________________________________<br>
Ale mailing list<br>
<a href="mailto:Ale@ale.org" target="_blank">Ale@ale.org</a><br>
<a href="http://mail.ale.org/mailman/listinfo/ale" target="_blank">http://mail.ale.org/mailman/listinfo/ale</a><br>
See JOBS, ANNOUNCE and SCHOOLS lists at<br>
<a href="http://mail.ale.org/mailman/listinfo" target="_blank">http://mail.ale.org/mailman/listinfo</a><br>
<br></blockquote></div><span></span><br></div></blockquote></div><br clear="all"><br>-- <br><div><a href="http://leamhall.blogspot.com/" target="_blank">Mind on a Mission</a></div>
</div></div>
<br>_______________________________________________<br>
Ale mailing list<br>
<a href="mailto:Ale@ale.org" target="_blank">Ale@ale.org</a><br>
<a href="http://mail.ale.org/mailman/listinfo/ale" target="_blank">http://mail.ale.org/mailman/listinfo/ale</a><br>
See JOBS, ANNOUNCE and SCHOOLS lists at<br>
<a href="http://mail.ale.org/mailman/listinfo" target="_blank">http://mail.ale.org/mailman/listinfo</a><br>
<br></blockquote></div>
</div></div><br>_______________________________________________<br>
Ale mailing list<br>
<a href="mailto:Ale@ale.org">Ale@ale.org</a><br>
<a href="http://mail.ale.org/mailman/listinfo/ale" target="_blank">http://mail.ale.org/mailman/listinfo/ale</a><br>
See JOBS, ANNOUNCE and SCHOOLS lists at<br>
<a href="http://mail.ale.org/mailman/listinfo" target="_blank">http://mail.ale.org/mailman/listinfo</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br> Ed Cashin <<a href="mailto:ecashin@noserose.net">ecashin@noserose.net</a>><br> <a href="http://noserose.net/e/">http://noserose.net/e/</a><br> <a href="http://www.coraid.com/">http://www.coraid.com/</a>
</div>