easy question, i hope.. 
Author Message
 easy question, i hope..

Ok, I am trying to use the function and I'm #including math.h.  There's a
ton of online references that say this should work, but when I compile it
I get this message:

gcc -g -Wall zscore.c main.c -o main
/tmp/ccevIzCM.o: In function `normalize':
/home/masseya/zscore.c:242: undefined reference to `sqrt'
collect2: ld returned 1 exit status

Why doesn't this work?  Is there an official reference that I should look
at to see if sqrt() is in a different header file?

Thanks for holding my hand for a newbie-ish question..

-Aaron



Fri, 04 Feb 2005 22:15:12 GMT  
 easy question, i hope..
Quote:

> Ok, I am trying to use the function and I'm #including math.h.  There's a
> ton of online references that say this should work, but when I compile it
> I get this message:

> gcc -g -Wall zscore.c main.c -o main
> /tmp/ccevIzCM.o: In function `normalize':
> /home/masseya/zscore.c:242: undefined reference to `sqrt'
> collect2: ld returned 1 exit status

> Why doesn't this work?  Is there an official reference that

 > I should look at [...]

Yes, there is the FAQ. :-)
http://www.eskimo.com/~scs/C-faq/q14.3.html

Jirka



Fri, 04 Feb 2005 22:27:56 GMT  
 easy question, i hope..

Quote:

> Ok, I am trying to use the function and I'm #including math.h.  There's a
> ton of online references that say this should work, but when I compile it
> I get this message:

> gcc -g -Wall zscore.c main.c -o main
> /tmp/ccevIzCM.o: In function `normalize':
> /home/masseya/zscore.c:242: undefined reference to `sqrt'
> collect2: ld returned 1 exit status

> Why doesn't this work?  Is there an official reference that I should look
> at to see if sqrt() is in a different header file?

> Thanks for holding my hand for a newbie-ish question..

> -Aaron

This isn't a C question, but a question specific to your compiler-linker
setup.  In your case, adding the magic word -lm to the end of that gcc
line should solve the problem.  The error message is from "ld" which is
your linker and it is complaining that it can't find the definition of sqrt.

-nrk.



Sat, 05 Feb 2005 02:27:54 GMT  
 easy question, i hope..

Quote:

> Ok, I am trying to use the function and I'm #including math.h.  There's a
> ton of online references that say this should work, but when I compile it
> I get this message:
> gcc -g -Wall zscore.c main.c -o main
> /tmp/ccevIzCM.o: In function `normalize':
> /home/masseya/zscore.c:242: undefined reference to `sqrt'
> collect2: ld returned 1 exit status
> Why doesn't this work?  Is there an official reference that I should look
> at to see if sqrt() is in a different header file?

Add a -lm to the compiler command line.  That links in the math libraries.

--
Joel



Sat, 05 Feb 2005 02:55:09 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Vector of string <--- Real easy question I hope

2. Get control's position (Easy question, I hope)!!

3. Easy question for U I hope !

4. Easy Question #2 I hope !

5. OLEDB.NET - an easy one (i hope)

6. @> two easy easy questions

7. 2 Simple (I Hope Questions)

8. I hope someone can explain the question.

9. a couple quick questions (i hope)

10. C Questions..Hope I can get an answer!

11. Simple Question I hope

12. Simple question (I hope)

 

 
Powered by phpBB® Forum Software