This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: gcc compiler, version egcs 1.1.1

>   My problem: I'm trying to declare and call math
> functions--specifically sin(x), cos(x), sqrt(x), pow(x, y).  When I
> call them and include math.h (or is it tgmath.h?) I get the message:
> "function undefined." When I declare them (ex: double sqrt(double))
> I get the same message.

I doubt that the message you get literally reads "function
undefined". It is very important that you quote error message
literally as they appear on the terminal.

> My question: What's the correct prototype format for these
> functions? (or more generally, how are they declared and called?)

You should never declare the functions yourself; instead, use the
appropriate header file. For sin/cos/sqrt/pow, the header file is
indeed math.h, so there is no need to declare the functions further.

I believe your problem is not that the functions where not declared,
but that no implementation was found, i.e. that the error message read

undefined reference to `sin'

In that case, you should tell the compiler to link with the math
library, i.e. you need to add -lm.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]