ofxCv macro error on X11

Hi :slight_smile: I cloned the ofxCv addon and tried running the Flow and Blur examples and I get this error:

/usr/include/opencv2/stitching.hpp:58:4: warning: Detected X11 'Status' macro definition, it can cause build conflicts. Please, include this header before any X11 headers. [-W#warnings]
#  warning Detected X11 'Status' macro definition, it can cause build conflicts. Please, include this header before any X11 headers.
   ^
/usr/include/opencv2/stitching.hpp:128:10: error: expected identifier or '{'
    enum Status
         ^
/usr/include/X11/Xlib.h:83:16: note: expanded from macro 'Status'
#define Status int
               ^
1 warning and 1 error generated.
Process failed with exit code 1.

Is it finding the wrong headers? I’m using ofxCv master (not stable) because with stable it complains about glm. I’m on Linux with QtCreator. Thank you!

this is a really annoying thing with X11 they define super common names like Status as macros so you need to include anything that defines any name that classes before including ofxCv

usually if you can include ofxCv only in the cpp file just include it as the first header and it should be ok.

if you need it in your .h it can be more tricky since anything including that header needs to include it before including ofMain so trying to keep ofxCv only in your cpp will make things easier if you need to add more classes

Thank you.

It seems to be more complicated. I moved everything from .h to .cpp, didn’t help. I deleted everything related to ofxCv, didn’t help. As soon as ‘ofxCv’ is listed inside of.addons in the .qbs file, I get that error.

For reference, here there’s a short explanation about this issue (which does not help):
https://bugs.freedesktop.org/show_bug.cgi?id=97359

Can I delete X11? :stuck_out_tongue:

Thinking about it i remember removing all direct includes to X from the core headers but there’ might be something missing i’ll take a look when i have a moment

Maybe it’s this one? https://github.com/openframeworks/openFrameworks/blob/19ec2688df9eecd818e333bef4753c302058de17/libs/openFrameworks/app/ofAppRunner.h#L111

yes, that’s probably it, can you check if if works now?

1 Like

It does! :thumbsup:

Hi, I’m having the same issue on Arch Linux, using stable branch of ofxCv and OF 0.9.8 … so what is the solution? I can’t seem to understand from your earlier conversation. Thanks for your help! Riccardo

I applied this change to the OF source code:
https://github.com/openframeworks/openFrameworks/commit/ba9975971f938159466a50d4b165632f11e40d03

Moving a line from one file to another.

Hi Arturo, thanks! Sorry I’m quite new to OF and C++ do I have to use the Nightly Build for Linux64 then? Or can I just make the change myself / apply patch and then recompile uising ./compileOF.sh ? I’m on 64bit ArchLinux. R

Hi! It was @hamoid posting Arturo’s photo :stuck_out_tongue:

You could use the nightly build, or you can just change that one line in your OF folder.

Remove #include <X11/Xlib.h> from libs/openFrameworks/app/ofAppRunner.h and put it into libs/openFrameworks/utils/ofSystemUtils.cpp after #include <thread>

I don’t think a recompile is required. Doesn’t it happen automatically?

Haha, sorry! :smile: well thank you @hamoid! I’ll give it a shot asap and report back!

Damn, I’m still getting the same error @hamoid … I’ve changed the lines and even recompiled using scripts/linux/compileOF.sh (no errors) but I still get the same error when running an ofxCv example. Why could this be? Thanks for your help!

In file included from /usr/include/opencv2/opencv.hpp:86:0,
                 from /home/thinkpad2000/Code/openFrameworks/addons/ofxCv/src/ofxCv.h:4,
                 from /home/thinkpad2000/Code/openFrameworks/addons/ofxCv/example-empty/src/ofApp.h:4,
                 from /home/thinkpad2000/Code/openFrameworks/addons/ofxCv/example-empty/src/main.cpp:1:
/usr/include/opencv2/stitching.hpp:58:4: warning: #warning Detected X11 'Status' macro definition, it can cause build conflicts. Please, include this header before any X11 headers. [-Wcpp]
 #  warning Detected X11 'Status' macro definition, it can cause build conflicts. Please, include this header before any X11 headers.
    ^~~~~~~
In file included from /usr/include/GL/glx.h:30:0,
                 from /home/thinkpad2000/Code/openFrameworks/libs/openFrameworks/utils/ofConstants.h:184,
                 from /home/thinkpad2000/Code/openFrameworks/libs/openFrameworks/ofMain.h:5,
                 from /home/thinkpad2000/Code/openFrameworks/addons/ofxCv/example-empty/src/ofApp.h:3,
                 from /home/thinkpad2000/Code/openFrameworks/addons/ofxCv/example-empty/src/ofApp.cpp:1:
/usr/include/opencv2/stitching.hpp:128:10: error: expected identifier before ‘int’
     enum Status
          ^
In file included from /usr/include/opencv2/opencv.hpp:86:0,
                 from /home/thinkpad2000/Code/openFrameworks/addons/ofxCv/src/ofxCv.h:4,
                 from /home/thinkpad2000/Code/openFrameworks/addons/ofxCv/example-empty/src/ofApp.h:4,
                 from /home/thinkpad2000/Code/openFrameworks/addons/ofxCv/example-empty/src/ofApp.cpp:1:
/usr/include/opencv2/stitching.hpp:129:5: error: expected unqualified-id before ‘{’ token
     {

Ok, maybe then @arturo should say :slight_smile: Did he remove more of those X11 includes between your version and the nightly? I see no such changes at https://github.com/openframeworks/openFrameworks/search?q=X11&type=Commits&utf8=✓

Does your code make use of ofSystemUtils.cpp, and then the X11 include ends up being part of your project, which conflicts with ofxCv’s use of the word Status?

Try the nightly? Greetings from another Arch Linux user :wink:

ps. Did you remove the line? or comment it out? I always wondered what happens if you do //#define <something>. Is the #define parsed first and replaced by the content of something, or is it ignored because of the // ?

Yes I just tried the Nightly Linux64 build and it did ALMOST compile, no more X11 Status keyword error but a new one :frowning: and in the build before I removed the lines instead of commenting out

/home/thinkpad2000/Downloads/of_nightly/addons/ofxCv/libs/ofxCv/src/Flow.cpp: In member function ‘std::vector<ofVec3f> ofxCv::FlowPyrLK::getFeatures()’:
/home/thinkpad2000/Downloads/of_nightly/addons/ofxCv/libs/ofxCv/src/Flow.cpp:170:26: error: could not convert ‘poly.ofPolyline_<T>::getVertices<glm::tvec3<float, (glm::precision)0u> >()’ from ‘std::vector<glm::tvec3<float, (glm::precision)0u>, std::allocator<glm::tvec3<float, (glm::precision)0u> > >’ to ‘std::vector<ofVec3f>’
   return poly.getVertices();

@hamoid Nevermind! I was using the stable branch of ofxCv - after switching back to master it compiles just fine :slight_smile: thanks a lot! I was almost thinking of going back to Ubuntu :stuck_out_tongue: although it’s probably not related to that at all anyway

Hi all,
i wonder after 5 years this issue still there…

trying to compile the computer_vision example fails.
That is the same problem as hamoid describes in here.

Target system/Environment:
Raspberry Pi 4 B / Debian Bullseye 32 Bits
gcc 10

\ ERROR: OpenCV related macro issue:

warning Detected X11 ‘Status’ macro definition, it can cause build conflicts. Please, include this header before any X11 headers.

/usr/include/opencv4/opencv2/stitching.hpp:152:10: error: expected identifier before ‘int’
152 | enum Status

/usr/include/opencv4/opencv2/stitching.hpp:153:5: error: expected unqualified-id before ‘{’ token
153 | {
| ^

/usr/include/opencv4/opencv2/stitching.hpp:152:10: error: expected identifier before ‘int’
152 | enum Status
| ^~~~~~

/usr/include/opencv4/opencv2/stitching.hpp:153:5: error: expected unqualified-id before ‘{’ token
153 | {
| ^

//

The hamoid FIX suggestion in the following files:
libs/openFrameworks/app/ofAppRunner.h
libs/openFrameworks/utils/ofSystemUtils.cpp

are already in of_v0.11.2_linuxarmv6l_release implemented. So i don’t need to change them.

how can i fix this?
Thanks for your help!

This is not an OF issue but OpenCV macro issue.
However OF should deliver consistence and error free examples that always compile on any platform OF supports.

If OF can’t compile with OpenCV than OF should point to the problem and deliver a
work around or better a fix.

The Status conflict exist only in the stitching.hpp file.
My workaround is to rename Status with XStatus.

Now i can compile OF with OpenCV.

Thanks for your help!

Thanks @Juan
Remember that OF is a community driven project, no one gets paid and there is no such thing as commanding what should be done or not. If issues arise, it is all of us who try to fix these, although as it is a voluntary thing there are times when some problems don’t get covered.
So, as you have found the solution to this problem, can you please make a Pull Request in github providing this fix? It will be really helpful and very much appreciated.

cheers

Thanks for the reply @roymacdonald

Don’t misunderstand me.

I don’t command at all. As you said , the community alone decides what should or should not be done.

My recommendation for this issue was to point out, that the quality of OF deployment can be increased with little effort.

I have created a workaround fix only for OpenCV/
of_v0.11.2_linuxarmv6l_release ruining under the raspberry pi with debian bullseye 32 bts.

It affects the /usr/include/opencv4/opencv2/stitching.hpp
file .

It has nothing to do with OF. That’s why there is no
OF pull request.

Regards
Juan


diff --git a/stitching.hpp b/stitching.hpp
index 05656a1..5d890e7 100644
--- a/stitching.hpp
+++ b/stitching.hpp
@@ -147,7 +147,7 @@ namespace cv
         static const double ORIG_RESOL;  // Initialized in stitcher.cpp
 #endif
 
-        enum Status {
+        enum EnumStatus {
             OK = 0,
             ERR_NEED_MORE_IMGS = 1,
             ERR_HOMOGRAPHY_EST_FAIL = 2,
@@ -265,13 +265,13 @@ namespace cv
 
         @param images Input images.
         @param masks Masks for each input image specifying where to look for keypoints (optional).
-        @return Status code.
+        @return EnumStatus code.
          */
-        CV_WRAP Status estimateTransform(InputArrayOfArrays images,
-                                         InputArrayOfArrays masks = noArray());
+        CV_WRAP EnumStatus estimateTransform(InputArrayOfArrays images,
+                                             InputArrayOfArrays masks = noArray());
 
         /** @overload */
-        CV_WRAP Status composePanorama(OutputArray pano);
+        CV_WRAP EnumStatus composePanorama(OutputArray pano);
         /** @brief These functions try to compose the given images (or images stored internally from
         the other function calls) into the final pano under the assumption that the image
         transformations were estimated before.
@@ -281,21 +281,21 @@ namespace cv
 
         @param images Input images.
         @param pano Final pano.
-        @return Status code.
+        @return EnumStatus code.
          */
-        CV_WRAP Status composePanorama(InputArrayOfArrays images, OutputArray pano);
+        CV_WRAP EnumStatus composePanorama(InputArrayOfArrays images, OutputArray pano);
 
         /** @overload */
-        CV_WRAP Status stitch(InputArrayOfArrays images, OutputArray pano);
+        CV_WRAP EnumStatus stitch(InputArrayOfArrays images, OutputArray pano);
         /** @brief These functions try to stitch the given images.
 
         @param images Input images.
         @param masks Masks for each input image specifying where to look for keypoints (optional).
         @param pano Final pano.
-        @return Status code.
+        @return EnumStatus code.
          */
-        CV_WRAP Status stitch(InputArrayOfArrays images, InputArrayOfArrays masks,
-                              OutputArray pano);
+        CV_WRAP EnumStatus stitch(InputArrayOfArrays images, InputArrayOfArrays masks,
+                                  OutputArray pano);
 
         std::vector<int> component() const { return indices_; }
         std::vector<detail::CameraParams> cameras() const { return cameras_; }
@@ -303,8 +303,8 @@ namespace cv
         UMat resultMask() const { return result_mask_; }
 
       private:
-        Status matchImages();
-        Status estimateCameraParams();
+        EnumStatus matchImages();
+        EnumStatus estimateCameraParams();
 
         double registr_resol_;
         double seam_est_resol_;

–eof–