This is the mail archive of the
mailing list for the GCC project.
Re: gcc compiler, version egcs 1.1.1
- To: jalright at ix dot netcom dot com
- Subject: Re: gcc compiler, version egcs 1.1.1
- From: "Martin v. Loewis" <martin at loewis dot home dot cs dot tu-berlin dot de>
- Date: Sat, 13 May 2000 22:39:47 +0200
- CC: help-gcc at gnu dot org
- References: <391D67EA.F2FFCA5D@ix.netcom.com>
> 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.