Tony> I've run into a surprising problem with math.h: it doesn't seems to
Tony> I'm writing C code to take the square root of a double. I have "#include
Tony> <math.h>" at the top, but when I compile (with cc) I get this error
Tony> /tmp/cca021002.o(.text+0x11a): undefined reference to `sqrt'
Okay, this is a linker error, not a compiler error. This means that,
in fact, the declarations in math.h have been read in (otherwise you'd
be getting a compiler error along the lines of "call to undeclared
function" and the error would be in a .c file), and therefore the
#include works fine. The linker just doesn't know where to find the
1. Read through math.h. Pretend you're a compiler/linker. Ask
yourself, "I have this declaration that sqrt() and sin() and such
exist; where's the actual code?"
2. Look for answers to this question on DejaNews or some such service.
3. Read just about any FAQ that deals with using the C language under
Unix. This question will be answered.
"Hey, Doug, do you mind if I push the Emergency Booth Self-Destruct Button?"
"Oh, sure, Dave, whatever...you _do_ know what that does, right?"