PDA

View Full Version : How to use cmath.h with Qt OpenSource and minGW?



awbaker
6th February 2006, 00:01
I'm using Qt 4.1.0 Open Source on Windows XP and haven't been able to use the fmod() function from within a dialog box method. A different post talks about adding options to the gcc command line, but I don't see how that applies to my config.

wysota
6th February 2006, 00:07
In what way you "haven't been able" to use it? What did the compiler complain about?

awbaker
6th February 2006, 00:11
The error message was:
fmod' undeclared (first use this function)

At the beginning of the cpp file, I have this stmt
#include <cmath.h>

Thanks,

jacek
6th February 2006, 00:15
Try:
#include <cmath>

wysota
6th February 2006, 00:15
Either:

#include <math.h>
a = fmod(x,y);
or:

#include <cmath>
a = ::fmod(x,y);

awbaker
6th February 2006, 00:22
Great!
I don't understand why including cmath.h doesn't work, but including cmath does, but for now I'm happy.

Thanks.

jacek
6th February 2006, 00:42
I don't understand why including cmath.h doesn't work, but including cmath does
Because there is no such header as "cmath.h". All standard C++ headers don't have a customary ".h" extension.

awbaker
6th February 2006, 00:50
Sure enough - I checked the mingw include library and none of the files have the .h extension. The confusion factor comes with the Qt include library where all files DO have the .h extension.

jacek
6th February 2006, 00:55
The confusion factor comes with the Qt include library where all files DO have the .h extension.
Not quite, in Qt4 both versions are available, but the one without ".h" is preferred.

Weaver
8th February 2006, 05:29
The C++ standard says that if you use #include <foo.h> that there is an actual file someplace called foo.h

Using the notation #include <foo> makes no assumption about the storage of the "foo" library, it just guarantees the availability of the foo functions to your program.


Also, the practical difference of <math.h> vs <cmath> is that the formers functions are automatically imported to the current namespace, while the latters aren't.