Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot Compile OpenCV 2.4.5 with VS 2013 RTM

Has anyone had any luck compiling openCV with VS 2013 RTM? I have tried and get a bunch of "min doesn't belong to namespace std" "max doesn't belong to namespace std" in the IlmImf module, and opencv_features2d doesn't compile with the following error:

opencv\modules\core\include\opencv2/core/core.hpp(4512): fatal error C1075: end of file found before the left brace '{' at '......\modules\features2d\src\features2d_init.cpp(187)' was matched

Since the latest CMake UI doesn't yet support building with 2013 (at least from the UI and I'm a noob), my process was configuring CMake for 2012, and then opening the generated solution with 2013 and upgrading the compiler to vc12.

I was able to get past the min/max errors by adding header includes for in the 'offending' files, but I am stumped by the full error I posted above.

Thanks

Update:

The accepted answer provides what is necessary to compile OpenCV in 32-bit debug and release, and 64-bit debug, but now the compiler fails to compile 64-bit release due to an internal compiler error. This is likely the compiler's fault at this point, but the answer is still solves many problems.

Update 2: So the 64-bit issue turned out to be a bug in the auto-vectorizer. Here is the corresponding workaround.

Hi, thanks for the great bug report. I confirm this is a bug in the compiler optimizer. We will fix it in a future release.

If you need a source code workaround, please turn the vectorizer off on the loop inside computeOrbDescriptor:

#pragma loop(no_vector)

for (int i = 0; i < dsize; ++i)

{

   **...**

That lets me build orb.cpp & stardetector.cpp.

If this issue is severe, causing critical business situations or blocking your product development or deployment, please go to http://support.microsoft.com or call 1-800-MICROSOFT for assistance. For Microsoft premier customers, please contact your administrator, your Technical Account Manager, or your Microsoft premier account representative.

I am closing this MSConnect item. Feel free to respond if you need anything else.

Thanks,

Eric Brumer - Microsoft Visual C++ Team

The connect bug can be found here. Unfortunately the real fix for this is postponed until a later date.

like image 623
Mranz Avatar asked Jul 01 '13 17:07

Mranz


3 Answers

I've managed to compile OpenCV 2.4.6 on VS2013 RC, but initially it had the same errors as in question. I've opened VS solution and fixed all error in two steps:

1) Replaced (Ctrl+H)

#include \<string\> 

to

#include <algorithm>\n#include <string>

in entire solution (be sure to enable RegExp in replace dialog)

2) In "modules/opencv_features2d/Src/features2d_init.cpp" changed line 184 to:

obj.info()->addParam(obj, "detector", (Ptr<Algorithm>&) obj.detector);

(search for "GridAdaptedFeatureDetector" in this file for other OpenCV versions)

like image 53
akazakov Avatar answered Oct 02 '22 23:10

akazakov


For the first issue:

http://blogs.msdn.com/b/vcblog/archive/2013/06/28/c-11-14-stl-features-fixes-and-breaking-changes-in-vs-2013.aspx

It is explicitly called out:

  • You must #include <algorithm> when calling std::min() or std::max().

Before due to the internal implementation of the VC++ libraries <string> would pull in these functions.

like image 44
Pete Steijn Avatar answered Oct 02 '22 23:10

Pete Steijn


Please see http://code.opencv.org/issues/3273 for more information on the internal compiler error issue.

like image 24
golubdr Avatar answered Oct 02 '22 23:10

golubdr