* Undefined reference to 'fmod'
@ 2006-06-11 4:35 James Colannino
2006-06-11 7:17 ` Steve Graegert
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: James Colannino @ 2006-06-11 4:35 UTC (permalink / raw)
Hey everyone. I included the math.h header, proceeded to use fmod(),
then got the following error:
/tmp/ccKQxpJi.o: In function `main':
04-03-calc.c:(.text+0x144): undefined reference to `fmod'
collect2: ld returned 1 exit status
Does anybody know why it won't link? fmod() is a part of the standard
library. This makes me very frustrated :( Thanks very much in advance.
James
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Undefined reference to 'fmod'
2006-06-11 4:35 Undefined reference to 'fmod' James Colannino
@ 2006-06-11 7:17 ` Steve Graegert
2006-06-11 7:18 ` Glynn Clements
[not found] ` <17547.46674.360830.637227@cerise.gclements.plus.com>
2 siblings, 0 replies; 7+ messages in thread
From: Steve Graegert @ 2006-06-11 7:17 UTC (permalink / raw)
To: James Colannino; +Cc: linux-c-programming
On 6/11/06, James Colannino <james@colannino.org> wrote:
> Hey everyone. I included the math.h header, proceeded to use fmod(),
> then got the following error:
>
> /tmp/ccKQxpJi.o: In function `main':
> 04-03-calc.c:(.text+0x144): undefined reference to `fmod'
> collect2: ld returned 1 exit status
>
> Does anybody know why it won't link? fmod() is a part of the standard
> library.
Use the -lm switch to link against libm.a (the math library).
\Steve
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Undefined reference to 'fmod'
2006-06-11 4:35 Undefined reference to 'fmod' James Colannino
2006-06-11 7:17 ` Steve Graegert
@ 2006-06-11 7:18 ` Glynn Clements
[not found] ` <17547.46674.360830.637227@cerise.gclements.plus.com>
2 siblings, 0 replies; 7+ messages in thread
From: Glynn Clements @ 2006-06-11 7:18 UTC (permalink / raw)
To: James Colannino
James Colannino wrote:
> Hey everyone. I included the math.h header, proceeded to use fmod(),
> then got the following error:
>
> /tmp/ccKQxpJi.o: In function `main':
> 04-03-calc.c:(.text+0x144): undefined reference to `fmod'
> collect2: ld returned 1 exit status
>
> Does anybody know why it won't link? fmod() is a part of the standard
> library.
No, fmod() is in libm, so you have to add -lm to the link command.
As a general rule, anything which uses <math.h> has to link against
libm.
--
Glynn Clements <glynn@gclements.plus.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Undefined reference to 'fmod'
[not found] ` <17547.46674.360830.637227@cerise.gclements.plus.com>
@ 2006-06-11 17:58 ` James Colannino
2006-06-11 19:20 ` Steve Graegert
2006-06-14 15:41 ` James Stevenson
0 siblings, 2 replies; 7+ messages in thread
From: James Colannino @ 2006-06-11 17:58 UTC (permalink / raw)
To: Linux C Programming List
Glynn Clements wrote:
> No, fmod() is in libm, so you have to add -lm to the link command.
>
> As a general rule, anything which uses <math.h> has to link against
> libm.
Interesting. Compiling with the argument -lm fixed my problem. That
leads me to another question: why are the functions found in math.h in a
separate library? I would have thought that all functions found in the
standard C library would be in glibc (The K&R book I'm reading said that
math.h is a part of the standard library.)
James
--
My blog: http://www.crazydrclaw.com/
My homepage: http://james.colannino.org/
"Blessed is the man, who having nothing to say, abstains from giving
wordy evidence of the fact." --George Eliot
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Undefined reference to 'fmod'
2006-06-11 17:58 ` James Colannino
@ 2006-06-11 19:20 ` Steve Graegert
2006-06-14 15:41 ` James Stevenson
1 sibling, 0 replies; 7+ messages in thread
From: Steve Graegert @ 2006-06-11 19:20 UTC (permalink / raw)
To: linux-c-programming
On 6/11/06, James Colannino <james@colannino.org> wrote:
> Glynn Clements wrote:
>
> > No, fmod() is in libm, so you have to add -lm to the link command.
> >
> > As a general rule, anything which uses <math.h> has to link against
> > libm.
>
> Interesting. Compiling with the argument -lm fixed my problem. That
> leads me to another question: why are the functions found in math.h in a
> separate library? I would have thought that all functions found in the
> standard C library would be in glibc (The K&R book I'm reading said that
> math.h is a part of the standard library.)
The functions in libm allow to create portable programs with
well-defined and standard-compliant behavior, e.g. when numerical
errors occur, and provide the application with a means to control
their behavior in abnormal cases via the matherr callback.
Additionally, they almost never rely on the features specific to
processor architectures and are thus slower and sometimes slightly
less accurate than the functions from libc.
libc functions OTOH are written for speed and exploitation of
CPU-specific features; they do not call matherr, and are therefore
much faster and, due to the extended 80-bit precision with which the
Intel FPUs carry their calculations, sometimes more accurate.
\Steve
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: Undefined reference to 'fmod'
2006-06-11 17:58 ` James Colannino
2006-06-11 19:20 ` Steve Graegert
@ 2006-06-14 15:41 ` James Stevenson
2006-06-15 0:20 ` Glynn Clements
1 sibling, 1 reply; 7+ messages in thread
From: James Stevenson @ 2006-06-14 15:41 UTC (permalink / raw)
To: 'James Colannino', 'Linux C Programming List'
Hi,
It cant be not all processors have floating point unit's Therefor it cannot
be in the main standard libary
> -----Original Message-----
> From: linux-c-programming-owner@vger.kernel.org [mailto:linux-c-
> programming-owner@vger.kernel.org] On Behalf Of James Colannino
> Sent: 11 June 2006 18:58
> To: Linux C Programming List
> Subject: Re: Undefined reference to 'fmod'
>
> Glynn Clements wrote:
>
> > No, fmod() is in libm, so you have to add -lm to the link command.
> >
> > As a general rule, anything which uses <math.h> has to link against
> > libm.
>
> Interesting. Compiling with the argument -lm fixed my problem. That
> leads me to another question: why are the functions found in math.h in a
> separate library? I would have thought that all functions found in the
> standard C library would be in glibc (The K&R book I'm reading said that
> math.h is a part of the standard library.)
>
> James
> --
> My blog: http://www.crazydrclaw.com/
> My homepage: http://james.colannino.org/
>
> "Blessed is the man, who having nothing to say, abstains from giving
> wordy evidence of the fact." --George Eliot
> -
> To unsubscribe from this list: send the line "unsubscribe linux-c-
> programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: Undefined reference to 'fmod'
2006-06-14 15:41 ` James Stevenson
@ 2006-06-15 0:20 ` Glynn Clements
0 siblings, 0 replies; 7+ messages in thread
From: Glynn Clements @ 2006-06-15 0:20 UTC (permalink / raw)
To: James Stevenson
Cc: 'James Colannino', 'Linux C Programming List'
James Stevenson wrote:
> > > No, fmod() is in libm, so you have to add -lm to the link command.
> > >
> > > As a general rule, anything which uses <math.h> has to link against
> > > libm.
> >
> > Interesting. Compiling with the argument -lm fixed my problem. That
> > leads me to another question: why are the functions found in math.h in a
> > separate library? I would have thought that all functions found in the
> > standard C library would be in glibc (The K&R book I'm reading said that
> > math.h is a part of the standard library.)
>
> It cant be not all processors have floating point unit's Therefor it cannot
> be in the main standard libary
There are some functions in libc which use floating-point. Also, FP is
part of the C language itself; on processors which don't support FP in
hardware, you just emulate it.
The reason for the use of a separate math library is more likely to be
so that you can have different versions for systems with and without
FP support. Implementing FP math functions using an FP emulation
library is likely to be more efficient that relying upon generic FP
emulation.
Generic FP emulation normally works by handling "illegal instruction"
exceptions, which occur if a CPU without FP support attempts to
execute a FP instruction. The exception handler then emulates the
instruction in software. Exception handling normally adds significant
overhead, so it's more efficient to replace FP instructions with calls
to functions in an FP emulation library.
--
Glynn Clements <glynn@gclements.plus.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2006-06-15 0:20 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-11 4:35 Undefined reference to 'fmod' James Colannino
2006-06-11 7:17 ` Steve Graegert
2006-06-11 7:18 ` Glynn Clements
[not found] ` <17547.46674.360830.637227@cerise.gclements.plus.com>
2006-06-11 17:58 ` James Colannino
2006-06-11 19:20 ` Steve Graegert
2006-06-14 15:41 ` James Stevenson
2006-06-15 0:20 ` Glynn Clements
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 NNTP newsgroup(s).