How do you include "math.h" In a .c file ?
I want to include "math.h" in a .c file in order to use powf and fabsf functions. When I do that, I get "warning: powf undefined;" and "error: Unresolved external" for the two functions ( powf and fabsf ) that I am using.
If I change the extension from .c to .cpp then it works and powf and fabsf are recognised. How do I make it to work with a .c extension?
thanks
[384 byte] By [
tirilo] at [2007-11-17 11:50:13]

# 1 Re: How do you include "math.h" In a .c file ?
Here is the notation from the MSDN. There is no cpp file indicated and ANSI compatibility is stated. Maybe it was the stdio.h ?
Requirements
Routine Required header Compatibility
pow, powf <math.h> ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP
For additional compatibility information, see Compatibility in the Introduction.
Libraries
All versions of the C run-time libraries.
Example
/* POW.C
*
*/
#include <math.h>
#include <stdio.h>
void main( void )
{
double x = 2.0, y = 3.0, z;
z = pow( x, y );
printf( "%.1f to the power of %.1f is %.1f\n", x, y, z );
}
Output
2.0 to the power of 3.0 is 8.0
Thank you for rating :)
# 2 Re: How do you include "math.h" In a .c file ?
Thanks.
Actually I just found out that my code compiles if I use pow instead of powf and fabs instead of fabsf. It seems like the optimized functions powf and fabsf don't get defined when I include "math.h" in a .c file but do get defined when I include "math.h" in a .cpp file. Strange.
Anyway, do you know how to include a cpp library in a .c file ? I am trying to use a library of functions written in C++. Once again it works when the file In which I do the #include is a .c extension. It doesn't work anymore when I just change the extension into .cpp
any suggestion?
tirilo at 2007-11-10 8:07:54 >
