Math.h and Ubuntu

Hi all. I have a code wrote in C++('.cpp') that I'm able to compile without problem in Windows. But when I try to compile in Ubuntu (g++ 4.4) I get the following errors:

Prog.cpp:39: error: ‘min’ was not declared in this scope
Prog.cpp:40: error: ‘max’ was not declared in this scope

The 'min' and 'max' are in the math.h library (I think because I'm not an expert).This is included in the code. searching on google I found differet solution that didn't solve my problem. One of these suggest:

#include <algorithm>

Another solution suggested is to compile adding '-lm'. In both cases I always get the same errors.
Do you know how can I fix my problem?Or, can you write a simple code to substitute at my 'min' and 'max'?

Thx,
closed account (S6k9GNh0)
http://cplusplus.com/reference/clibrary/cmath/

As you can see, min and max are not part of the cmath library.
However: http://cplusplus.com/reference/algorithm/

As you can see now, there is indeed min and max members here. The error makes me believe that you didn't include algorithm or it would give a different error or maybe perhaps you're using the functions incorrectly. If you can send us the entire example, I can probably help further.
Last edited on
It's about 4k rows.....I can only write the part under exam:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <string.h>
            ..............
            if(x >= 0 && x <width && y >= 0 && y <height)
            {
               check[0]=check[1]=0;
            	for(n=0; n<2; n++)
               {
                  v_sup[0]=min(v[n*4+0],v[n*4+2]);
                  v_sup[1]=max(v[n*4+0],v[n*4+2]);
            ..............

Last edited on
How about if you use std::min and std::max rather than min and max? Don't forget to #include <algorithm> as computerquip said.
Last edited on
Topic archived. No new replies allowed.