[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: cos() in math.h ?

On Thu, 3 Aug 2000, Christophe TROESTLER wrote:

> simply need to include `math.h'.  However, when I compile, I got the
> error:
> 	/tmp/cc9WOsLC.o(.text+0x16): undefined reference to `cos'
> 	collect2: ld returned 1 exit status

This is actually a linker error - undefined references happen when the
linker (which might be called by the compiler) tries to assemble the
object files into an executable, but can't find all the function calls
that the program wants to make.  cos() is in the math library, libm.a.  So
you need to add -lm to the command line.

Including math.h will allow the compiler to compile the object code
(otherwise you would get warnings or errors about the function declaration
for cos()) but the actual code that does the computation is in libm.

Reply to: