Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
426 views
in Technique[技术] by (71.8m points)

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

I'm trying to build OpenCV 2.4.6 on Windows 8 in Visual Studio 2012. Having downloaded the source from https://github.com/Itseez/opencv I generate (leaving the default configuration) using cmake and then load the resulting file ALL_BUILD.vcxproj into Visual Studio 2012. I then try to build it. Several of the modules do indeed build (e.g. core, flann, imgproc, ...) but I am trying to build highgui so that I can use the PDB file for debugging my code (which fails to open a video file). The build errors start with this and many similar errors:

error C2039: 'max' : is not a member of 'std' C:OpenCV2.4.63rdpartyopenexrImathImathMatrixAlgo.cpp 1094 1 IlmImf

One fix for errors like this (e.g. in this answer) is to add #include <algorithm> to the failing files. I tried that on a few files and it seems to work but I'm nervous about locally changing the source for a popular library. It must build on Windows (you can download the binaries, though not the PDB files, from the OpenCV sourceforge site) so I would like to understand how to build it on my machine without changing the source.

Am I missing something out in the configuration step? Is there some path setting etc. missing on my machine? Why am I getting these errors and how should I fix them?

========== EDIT ==========

Looking at the directory path this appears to be a problem with one of the 3rd party dependencies, OpenEXR. Looking on Github it appears to be version 1.7.1 of OpenEXR that is used in OpenCV 2.4.6. The instructions in the OpenCV's Quick Start Installation on Windows state:

  • In case of the Eigen library it is again a case of download and extract to the D:/OpenCV/dep directory.
  • Same as above with OpenEXR.

so I downloaded the OpenEXR 1.7.1 source code release and extracted the resulting files putting the directory openexr-1.7.1 into C:OpenCV2.4.6dep.

Then I ran cmake and tried to build the resulting Visual Studio solution. Sadly I see the same errors.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...