I can't seem to use pow()

M

Mark Healey

I'm using gcc on a fedora 3 system here are what I think the relevant
lines are:

#include <math.h>

[a bunch of stuff snipped]

r=pow(2,z);

When I compile I get

/tmp/ccg0U2N1.o(.text+0xd9): In function `generateMap':
: undefined reference to `pow'
collect2: ld returned 1 exit status

Why is this?
 
K

Keith Thompson

Mark Healey said:
I'm using gcc on a fedora 3 system here are what I think the relevant
lines are:

#include <math.h>

[a bunch of stuff snipped]

r=pow(2,z);

When I compile I get

/tmp/ccg0U2N1.o(.text+0xd9): In function `generateMap':
: undefined reference to `pow'
collect2: ld returned 1 exit status

Why is this?

<http://www.c-faq.com/fp/libm.html>
 
J

Joe Wright

Mark said:
I'm using gcc on a fedora 3 system here are what I think the relevant
lines are:

#include <math.h>

[a bunch of stuff snipped]

r=pow(2,z);

When I compile I get

/tmp/ccg0U2N1.o(.text+0xd9): In function `generateMap':
: undefined reference to `pow'
collect2: ld returned 1 exit status

Why is this?
You haven't linked in the math library. That makes you new to C. Being
that new, how did you find this newsgroup?

Please, before you post again, read the stuff at..

http://c-faq.com
 
K

Keith Thompson

Joe Wright said:
Mark said:
I'm using gcc on a fedora 3 system here are what I think the relevant
lines are:
#include <math.h>
[a bunch of stuff snipped]
r=pow(2,z);
When I compile I get /tmp/ccg0U2N1.o(.text+0xd9): In function
`generateMap':
: undefined reference to `pow'
collect2: ld returned 1 exit status
Why is this?
You haven't linked in the math library. That makes you new to C. Being
that new, how did you find this newsgroup?

Or he's been using compilers that link the math library without being
told to do so. Or he hasn't been using said:
Please, before you post again, read the stuff at..

http://c-faq.com

To be fair, that particular question can be difficult to find unless
you already know about it. The question refers to "sin" and "cos",
not to "pow". (On the other hand, it also refers to <math.h>, and
it's in the section on floating point, so it's not *completely*
hidden.)
 
A

A. Sinan Unur

Mark Healey a écrit :
I'm using gcc on a fedora 3 system here are what I think the relevant
lines are:

#include <math.h>

[a bunch of stuff snipped]

r=pow(2,z);

When I compile I get

/tmp/ccg0U2N1.o(.text+0xd9): In function `generateMap':
: undefined reference to `pow'
collect2: ld returned 1 exit status

Why is this?
Because that stupid compiler doesn't include the C library by default.

It is up to the user to include it, and for people that do not have
"experience" with that compiler it will be a discovery....

Or, people could actually read the FAQ list before posting here:

http://www.c-faq.com/fp/libm.html

Sinan

--
A. Sinan Unur <[email protected]>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
 
M

Mark Healey

Mark Healey said:
I'm using gcc on a fedora 3 system here are what I think the relevant
lines are:

#include <math.h>

[a bunch of stuff snipped]

r=pow(2,z);

When I compile I get

/tmp/ccg0U2N1.o(.text+0xd9): In function `generateMap':
: undefined reference to `pow'
collect2: ld returned 1 exit status

Why is this?

<http://www.c-faq.com/fp/libm.html>

Thanks, that was it.

Now, why is it that you have to do this with some libraries and not
others? I did "man math.h" and it wasn't mentioned.

Secondly. This is such a common action, why isn't there a operator for
it?
 
M

Mark Healey

You haven't linked in the math library. That makes you new to C.

Well, I've dabbled in it forever.
Being
that new, how did you find this newsgroup?

I don't see the connection there. comp.lang.c it a pretty intuitive group
name to look for.
 
C

Chris Torek

Now, why is it that you have to [link against a separate math library]
and not others? I did "man math.h" and it wasn't mentioned.

Just a (silly) tradition. There is no reason the "compile ANSI C
program" command should not link against -lm automatically, just as
it links against -lc. But traditionally it does not. Of course,
this same tradition predates ANSI C entirely, and there was no
reason not to change the behavior when the command was changed to
default to (nearly-) ANSI C.

A separated-out math library does make a certain amount of sense
(in fact, I can argue for dividing things up even further), but
"won't look for it unless you specifically ask" does *not* make
sense. It is merely "traditional", and "it's traditional" is
shorthand for "we had a good reason once, but we have forgotten
what it was." :)
 
C

CBFalconer

Chris said:
.... snip ...

A separated-out math library does make a certain amount of sense
(in fact, I can argue for dividing things up even further), but
"won't look for it unless you specifically ask" does *not* make
sense. It is merely "traditional", and "it's traditional" is
shorthand for "we had a good reason once, but we have forgotten
what it was." :)

How about: It takes a long time to search and link programs, and
that can be cut significantly by having a smaller tauter library to
handle the 90% that don't use floating point. Bear in mind that we
are using floppy disks and a 5 Mhz 8086.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
 
R

Richard Bos

Joe Wright said:
You haven't linked in the math library. That makes you new to C.

No, it makes him new to geriatric, designed-for-1980 implementations.

Richard
 
C

Chris Dollin

Mark said:
I'm using gcc on a fedora 3 system here are what I think the relevant
lines are:

#include <math.h>

[a bunch of stuff snipped]

r=pow(2,z);

When I compile I get

/tmp/ccg0U2N1.o(.text+0xd9): In function `generateMap':
: undefined reference to `pow'
collect2: ld returned 1 exit status

Why is this?

I believe this is a FAQ (hint).

For hysterical raisins, you need the -lm flag.
 
G

Giorgos Keramidas

Mark Healey said:
Mark Healey said:
I'm using gcc on a fedora 3 system here are what I think the relevant
lines are:

#include <math.h>

[a bunch of stuff snipped]

r=pow(2,z);

When I compile I get

/tmp/ccg0U2N1.o(.text+0xd9): In function `generateMap':
: undefined reference to `pow'
collect2: ld returned 1 exit status

Why is this?

<http://www.c-faq.com/fp/libm.html>

Thanks, that was it.

Now, why is it that you have to do this with some libraries and not
others? I did "man math.h" and it wasn't mentioned.

That's a documentation problem of your particular implementation.

In my manpage set here, I can read:

% $ man pow
% EXP(3) FreeBSD Library Functions Manual EXP(3)
%
% NAME
% exp, expf, exp2, exp2f, expm1, expm1f, log, logf,
% log10, log10f, log1p, log1pf, pow, powf -- exponential,
% logarithm, power functions
%
% LIBRARY
% Math Library (libm, -lm)
%
% SYNOPSIS
% #include <math.h>

It's nice to have a manpage of the math functions that points both to
the <math.h> header and the -lm library, but this is hardly related to
the C language. It's an implementation feature.

- Giorgos
 
J

jacob navia

Mark Healey a écrit :
I'm using gcc on a fedora 3 system here are what I think the relevant
lines are:

#include <math.h>

[a bunch of stuff snipped]

r=pow(2,z);

When I compile I get

/tmp/ccg0U2N1.o(.text+0xd9): In function `generateMap':
: undefined reference to `pow'
collect2: ld returned 1 exit status

Why is this?
Because that stupid compiler doesn't include the C library by default.
It is up to the user to include it, and for people that do not have
"experience" with that compiler it will be a discovery....

gcc myprog.c -lm

That cryptic "-lm" means include the math library, include pow, cos, etc.

They will never change that dammed "feature" and we will have to hear
this kind of complaints till the end of times.
 

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,176
Messages
2,570,950
Members
47,503
Latest member
supremedee

Latest Threads

Top