'min (& max) not a member of std' errors when building OpenCV 2.4.6 on Windows 8 for Visual Studio 2012

I was stumbling on the same issue while compiling OpenEXR. Then I found the solution googling for openexr std::min.

There is an issue opened on OpenCV where it says that, when using VS2013 Preview, you must add the line #include <algorithm> in the file where you're using std::min and std::max.

I put that line into the files where these methods are called and voilà! Compilation succeeded.


You probably need to #define NOMINMAX. Try putting it before any other includes.
If that helps, then put in the you project's preprocessor defines.

There's lots of info about this, just search for NOMINMAX. Here's one post about it.