Redeclaration issue [closed]

asked 2015-01-09 15:00:52 -0600

gleberof gravatar image

updated 2015-01-09 15:15:24 -0600

berak gravatar image

I'm trying to build OpenCV project (cpp) with following inclusions:

#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui/highgui.hpp"

and getting an error during the make "redeclaration issues.

It happens because of imgcodecs.hpp contains declaration:

 enum {
   IMREAD_UNCHANGED  = -1, // 8bit, color or not
   IMREAD_GRAYSCALE  = 0,  // 8bit, gray
   IMREAD_COLOR      = 1,  // ?, color
   IMREAD_ANYDEPTH   = 2,  // any depth, ?
   IMREAD_ANYCOLOR   = 4,  // ?, any color
   IMREAD_LOAD_GDAL  = 8   // Use gdal driver
   };

And highgui.hpp contains basically the same:

 enum {
// 8bit, color or not
IMREAD_UNCHANGED  =-1,
// 8bit, gray
IMREAD_GRAYSCALE  =0,
// ?, color
IMREAD_COLOR      =1,
// any depth, ?
IMREAD_ANYDEPTH   =2,
// ?, any color
IMREAD_ANYCOLOR   =4
};

Is any way to fix it without changing hpp files of OpenCV?

I'm really newbie at c++ thus my question could be dummy (sorry for that)

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by gleberof
close date 2015-01-09 16:27:33.937169

Comments

1

which compiler/os ?

could you come up with a minimal test case proving it ?

berak gravatar imageberak ( 2015-01-09 15:14:32 -0600 )edit
1

i'm using cmake make combo.Ubuntu 14.04.

I found out that standard sample squares.cpp use the same combination on includes. Can't compile it either (with same error).

gleberof gravatar imagegleberof ( 2015-01-09 15:53:47 -0600 )edit
2

if you just could add the exact error ?

berak gravatar imageberak ( 2015-01-09 15:56:23 -0600 )edit

This can be solved by adding include guards only. Mentioned here for example. No way of avoiding this. Someone should make a PR!

StevenPuttemans gravatar imageStevenPuttemans ( 2015-01-09 16:10:43 -0600 )edit

^^ if i'm not missing something, there are include guards already

(and they would not help against duplicate enums in different headers in the same namespace).

but again, can't reproduce the error.

berak gravatar imageberak ( 2015-01-09 16:15:30 -0600 )edit

berak, thank you for pushing me in right direction. Once I installing opencv i've download and compile version form page http://opencv.org/downloads.html and it seems mistakes is there. Once I take git version all troubles disappeared. Thanks you a lot again.

gleberof gravatar imagegleberof ( 2015-01-09 16:26:53 -0600 )edit
1

well,now call me confused..

berak gravatar imageberak ( 2015-01-09 16:33:36 -0600 )edit
1

In the beginning I have downloaded 2 versions 2.4.10 - by link and git (which is actually 3 beta) I do not understand the difference for that moment. I have compiled both but 2.4.10 was in a second turn. But once I have try examples I took them from 3 beta - which clause the multiple errors.

for instance for 2.4.10: > include "opencv2/imgproc/imgproc.hpp" include "opencv2/highgui/highgui.hpp"

but for 3 beta: > include "opencv2/imgcodecs.hpp" include "opencv2/highgui/highgui.hpp"

Conclusion: I've done stupid thing in the very begginig

gleberof gravatar imagegleberof ( 2015-01-10 02:02:02 -0600 )edit

so what was the solution ???

franken gravatar imagefranken ( 2015-08-05 04:38:11 -0600 )edit
1

@franken, look at his last reply. He mixed up 2.41 and 3.0 installations.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-08-05 05:34:57 -0600 )edit