public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* About -lm switch used for linking math.h
@ 2012-01-27  3:33 Avinash Sonawane
  2012-01-27 14:55 ` Tim Prince
  0 siblings, 1 reply; 2+ messages in thread
From: Avinash Sonawane @ 2012-01-27  3:33 UTC (permalink / raw)
  To: gcc-help

Sir,
I am using gcc 4.6.1.
I have few questions regarding -lm switch. Please kindly guide me for the same.

1) Why I need to use -lm flag for math.h even if I had declared the
#include <math.h> in the code?
2) If it's all about linking the library then why I don't have to do
the same thing with stdio.h too?
3) Or we have to add the -l'library' switch for every library excluding stdio.h?
4) In case if the -l'library' switch is used for some specific
libraries only then please direct me to the complete list of such
libraries.

Thanks.

--
Avinash Sonawane
PICT Pune
India

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: About -lm switch used for linking math.h
  2012-01-27  3:33 About -lm switch used for linking math.h Avinash Sonawane
@ 2012-01-27 14:55 ` Tim Prince
  0 siblings, 0 replies; 2+ messages in thread
From: Tim Prince @ 2012-01-27 14:55 UTC (permalink / raw)
  To: gcc-help

  On 01/26/2012 04:57 PM, Avinash Sonawane wrote:
> Sir,
> I am using gcc 4.6.1.
> I have few questions regarding -lm switch. Please kindly guide me for the same.
>
> 1) Why I need to use -lm flag for math.h even if I had declared the
> #include<math.h>  in the code?
> 2) If it's all about linking the library then why I don't have to do
> the same thing with stdio.h too?
> 3) Or we have to add the -l'library' switch for every library excluding stdio.h?
> 4) In case if the -l'library' switch is used for some specific
> libraries only then please direct me to the complete list of such
> libraries.
>
> Thanks.
>
> --
> Avinash Sonawane
> PICT Pune
> India
1.  This depends on which gcc language you use.  Requirement to set -lm 
explicitly is traditional "legacy" for C, but not for e.g. fortran, 
C++,....  It's unusual for a compiler to keep a list of headers you 
include and figure out the corresponding libraries required at link time.
2. <stdio.h> library support is always searched in C programs, 
regardless of your use of the header.
4.  As gcc itself doesn't supply many of the standard C library 
functions, you must use the facilities of your implementation (possibly 
linux, possibly something entirely different) to see which libraries are 
available.  gcc -v may show you which libraries are searched.

-- 
Tim Prince

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-01-26 22:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-27  3:33 About -lm switch used for linking math.h Avinash Sonawane
2012-01-27 14:55 ` Tim Prince

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).