math.h

Joel Sherrill joel.sherrill at OARcorp.com
Thu Sep 4 16:04:12 UTC 2003


Bert wrote:

> Hi, here is a newbie's question:
> i want RTEMS to do some simple calculations,
> so there are functions like "sin(x)" and
> "cos(x)" in the codes.
> but when i compile the codes, it tells me
> that "undefined reference to sin" and
> "undefined reference to cos" ...
> i have added "#include <math.h>" to the
> source code, what else should i do?

FYI this is a standard C FAQ.

math funcitons are in libm.a.  This is the
same with almost any C Compiler installation
native or cross.

You have to link your application with the math
library. This should be accomplished by getting
"-lm" added to the command that links the
application.  For simple native gcc cases, it is
something like this:

   gcc hello.c -lm -o hello

--joel

>               Bert
> ----------------------------------------------
> Óµ±§ÀËÂþ£¬³¢ÊÔ¼¤Ç飬¼ÓÈë¿¡ÄÐÃÀÅ®µÄ¼¤Çé½»ÓÑÀÖÔ° 
> http://y.21cn.com 
> 21CNÐÂÎÅÖÐÐÄ£ºÐÂÎÅÌìÌì¶Á£¬Ç¿µµÖð¸öÊý 
> http://news.21cn.com 
> ¸öÈËÍøÕ¾Á÷Á¿±ä½ðÇ®£¬»¶Ó­¼ÓÈë21CNÓʼþÁªÃË£¡ 
> http://mail.21cn.com/alliance/ 
> ÂêÀöÑÇ¿­ÀòÔÙÏÖ»¨ºûµû±¾É«£¨×éͼ£© 
> http://news.21cn.com/social/ 
> 
> 
> 
> 





More information about the users mailing list