How will you know about the libraries

N

Neo

I am using linux for my c programs and while compiling I some times
have to use -lm for math libraries ..

that is linker option,

but how will I know the library which I have to link ... meaning
math will be with -lm
etc ?
please help ... in linker options
 
W

Walter Roberson

I am using linux for my c programs and while compiling I some times
have to use -lm for math libraries ..
that is linker option,
but how will I know the library which I have to link ... meaning
math will be with -lm
etc ?

On unix, you read the man page for the function you are interested
in, and you look at the 'see also' section, which will refer
you to the 'intro' man page for the appropriate section. You
read the intro man page, and it tells you which libraries you
need to link in.
 
C

Chris Croughton

I am using linux for my c programs and while compiling I some times
have to use -lm for math libraries ..

that is linker option,

but how will I know the library which I have to link ... meaning
math will be with -lm
etc ?
please help ... in linker options

Well, for Unix-like systems you can use man <name_of_function> which
will tell you the header files you need to include and the libraries (if
not default).

However, many people regard this 'feature' of GCC (not including -lm by
default) as a bug, because a C compiler should arguably include any
libraries necessary to provide the standard functions without having
to do some system-dependent thing. The overhead is minimal (if there
are no functions still unlinked, it doesn't even have to read the extra
library, and no extra code should be linked if the functions in -lm
aren't needed). Indeed, the library supplied with the Cygwin port has
the maths functions in it so -lm isn't needed.

Chris C
 
M

Mark McIntyre

However, many people regard this 'feature' of GCC (not including -lm by
default) as a bug,

its worth noting that this isn't a GCC feature so much as a feature of
most early compilers. Some compilers even required you to *use* some
FP in main() to get the lib linked.
because a C compiler should arguably include any
libraries necessary to provide the standard functions without having
to do some system-dependent thing.

I agree with this.
The overhead is minimal

on a modern PC, yes. Not so on an original IBM-PC, or on many non-PC
implementations.
the library supplied with the Cygwin port has
the maths functions in it so -lm isn't needed.

so long as it silently ignores the -lm if you do include it. Otherwise
thered be a lot of broken makefiles.... :)
 
S

SM Ryan

#
# I am using linux for my c programs and while compiling I some times
# have to use -lm for math libraries ..
#
# that is linker option,
#
# but how will I know the library which I have to link ... meaning
# math will be with -lm
# etc ?

If you're lucky, it's included upfront in the interface documentation.
Usually if it's mentionned at all, it's one obscure sentence deep in
build notes. Sucks, but that's the accepted practice.
 
A

Alan Balmer

its worth noting that this isn't a GCC feature so much as a feature of
most early compilers. Some compilers even required you to *use* some
FP in main() to get the lib linked.

Many (most?) of those early compilers gave you a choice of math
libraries, for one reason or another (hardware fpp vs software fpp vs
emulated hardware vs no fpp, for example). A common way to do this was
to choose which library to link with.
 
L

Lawrence Kirby

On Sat, 09 Apr 2005 23:15:06 +0100, Chris Croughton wrote:

....
However, many people regard this 'feature' of GCC (not including -lm by
default) as a bug, because a C compiler should arguably include any
libraries necessary to provide the standard functions without having
to do some system-dependent thing.

It isn't a bug as such, because it is almost certainly deliberate and it
is not a conformance issue. Many compilers are conforming by default and
require you to give extra options to make them conforming (or the best
approximation to it). There is for example -ansi in gcc or -stdc= . A
compiler doesn't have to be conforming by default, there just needs to be
a way to invoke it as such.
The overhead is minimal (if there
are no functions still unlinked, it doesn't even have to read the extra
library, and no extra code should be linked if the functions in -lm
aren't needed). Indeed, the library supplied with the Cygwin port has
the maths functions in it so -lm isn't needed.

I agree that it isn't obvious what is gained by not making -lm implicit
these days.

Lawrence
 
J

Joe Wright

Lawrence said:
On Sat, 09 Apr 2005 23:15:06 +0100, Chris Croughton wrote:

...




It isn't a bug as such, because it is almost certainly deliberate and it
is not a conformance issue. Many compilers are conforming by default and
require you to give extra options to make them conforming (or the best
approximation to it). There is for example -ansi in gcc or -stdc= . A
compiler doesn't have to be conforming by default, there just needs to be
a way to invoke it as such.




I agree that it isn't obvious what is gained by not making -lm implicit
these days.

Lawrence

Probably just comfort with old habits. It also occurs to me that I
haven't typed 'gcc' and '-lm' for a long time. I use short scripts or
makefiles to invoke the compiler.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top