Discussion:
Error using math.h
(too old to reply)
Javid Sumayya
2004-01-18 21:31:03 UTC
Permalink
hi

I am having problems with using the power function in math.h
I have included the math.h file by writing #include <math.h>
and used the power function by calling pow(x,y)...where x and
y are two double variables
But for some reason it is giving me an error saying
"undefined reference to pow".

Thankx
Sherman
2004-01-20 03:07:59 UTC
Permalink
Is it just problems with "pow"? Cuz for me no matter what function I tried
using, it still gave me "undefined referene to (the function)".
And i #include <math.h> already so y is it still happening?

Sherman
Post by Javid Sumayya
hi
I am having problems with using the power function in math.h
I have included the math.h file by writing #include <math.h>
and used the power function by calling pow(x,y)...where x and
y are two double variables
But for some reason it is giving me an error saying
"undefined reference to pow".
Thankx
Robert Chang
2004-01-20 15:11:00 UTC
Permalink
Try adding -lm

Eg: gcc -o foo foo.c -lm
Post by Javid Sumayya
hi
I am having problems with using the power function in math.h
I have included the math.h file by writing #include <math.h>
and used the power function by calling pow(x,y)...where x and
y are two double variables
But for some reason it is giving me an error saying
"undefined reference to pow".
Thankx
Alexander Smith
2004-01-20 16:55:13 UTC
Permalink
In general, if you want to use <math.h>, you need to link your program
with the math library. This is what the "-lm" command does. In a Makefile,
the -lm would be added to the line that links all of your object files
together into the executable file.

However, for lab 1, you are not allowed to modify the Makefile. This means
that for lab 1, you cannot use math.h. You don't actually need any
functions in it anyways - not even pow(). You should be able to do the lab
without it.

Alexander
Post by Robert Chang
Try adding -lm
Eg: gcc -o foo foo.c -lm
Post by Javid Sumayya
hi
I am having problems with using the power function in math.h
I have included the math.h file by writing #include <math.h>
and used the power function by calling pow(x,y)...where x and
y are two double variables
But for some reason it is giving me an error saying
"undefined reference to pow".
Thankx
Loading...