Skip to content

vlc FTBFS with opencv-3.4.1 #10963

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
chris2553 opened this issue Feb 28, 2018 · 16 comments
Open

vlc FTBFS with opencv-3.4.1 #10963

chris2553 opened this issue Feb 28, 2018 · 16 comments

Comments

@chris2553
Copy link

chris2553 commented Feb 28, 2018

System information (version)
  • OpenCV => 3.4.1
  • Operating System / Platform => Linux
  • Compiler => gcc-7-20180222 (a 7.3.1 snapshot)

vlc-3.0.1 fails to build against opencv-3.4.1, because the C compiler produces and error at line 485 of /usr/include/opencv2/core/cvdef.h. The error message is:

           /usr/include/opencv2/core/cvdef.h:485:1: error: unknown type name 'namespace'  

This is because the C compiler is trying to compile C++ code.

Steps to reproduce
  1. build and install opencv-3.4.1
  2. configure vlc-3.0.1 to include opencv and then run make
Proposed fix

The following patch to opencv allows the build of vlc to complete:

--- opencv-3.4.1/modules/core/include/opencv2/core/cvdef.h.orig	2018-02-28 10:16:45.000320632 +0000
+++ opencv-3.4.1/modules/core/include/opencv2/core/cvdef.h	2018-02-28 10:34:30.852346927 +0000
@@ -454,6 +454,7 @@ Cv64suf;
 
 
 // Integer types portatibility
+#if defined __cplusplus
 #ifdef OPENCV_STDINT_HEADER
 #include OPENCV_STDINT_HEADER
 #else
@@ -494,6 +495,9 @@ typedef ::uint64_t uint64_t;
 }
 #endif
 #endif
+#else
+#include <stdint.h>
+#endif
 
 
 //! @}

With the patched opencv installed, I have also built the frei0r-plugin-1.6.0, gstreamer-plugins-bad-1.12.4 and LiVES-2.8.7, all of which use opencv (although I don't know whether they failed against an unpatched version)

@alalek
Copy link
Member

alalek commented Feb 28, 2018

OpenCV 3.x doesn't not support C compilation mode officially. There are still legacy C API calls (from OpenCV 1.x) but they should be compiled in C++ compilation mode.
Even if you succeeded to build code with C compiler (and avoid cvRound problem: #6585) it would lead to terrible behavior like #6221 or silent crashes in case of raised C++ exceptions.
All new algorithms in OpenCV are written in C++, so there are no benefits to use OpenCV 3.x in C programs.

Good solution for C programs is FFI C bindings, but we don't have them (see some discussion here).

@chris2553
Copy link
Author

chris2553 commented Feb 28, 2018 via email

@alalek
Copy link
Member

alalek commented Feb 28, 2018

OpenCV 2.4.x has some chance to work properly, but we don't run "native C" tests anymore.

@AdamWill
Copy link

AdamWill commented Mar 5, 2018

This also breaks libfreenect, FWIW:

https://koji.fedoraproject.org/koji/taskinfo?taskID=25506808

I'll look at whether libfreenect can/should be building for C++ not C.

@jiapei100
Copy link

Trying to build the most recent mrpt, this issue persists...
It looks highgui also has some problem?

[ 53%] Building CXX object libs/vision/CMakeFiles/mrpt-vision.dir/src/faster/faster_corner_9.cpp.o
In file included from /usr/local/include/opencv2/core/core_c.h:48:0,
                 from /media/jiapei/Data/Downloads/robotics/mrpt/mrpt/libs/img/include/mrpt/otherlibs/do_opencv_includes.h:27,
                 from /media/jiapei/Data/Downloads/robotics/mrpt/mrpt/libs/vision/src/sift-hess/utils.h:15,
                 from /media/jiapei/Data/Downloads/robotics/mrpt/mrpt/libs/vision/src/sift-hess/utils.c:10:
/usr/local/include/opencv2/highgui/highgui_c.h:139:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘:’ token
 CVAPI(cv::Rect)cvGetWindowImageRect(const char* name);
 ^
In file included from /usr/local/include/opencv2/core/core_c.h:48:0,
                 from /media/jiapei/Data/Downloads/robotics/mrpt/mrpt/libs/img/include/mrpt/otherlibs/do_opencv_includes.h:27,
                 from /media/jiapei/Data/Downloads/robotics/mrpt/mrpt/libs/vision/src/sift-hess/sift.h:15,
                 from /media/jiapei/Data/Downloads/robotics/mrpt/mrpt/libs/vision/src/sift-hess/sift.c:10:
/usr/local/include/opencv2/highgui/highgui_c.h:139:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘:’ token
 CVAPI(cv::Rect)cvGetWindowImageRect(const char* name);
 ^
In file included from /usr/local/include/opencv2/core/core_c.h:48:0,
                 from /media/jiapei/Data/Downloads/robotics/mrpt/mrpt/libs/img/include/mrpt/otherlibs/do_opencv_includes.h:27,
                 from /media/jiapei/Data/Downloads/robotics/mrpt/mrpt/libs/vision/src/sift-hess/utils.h:15,
                 from /media/jiapei/Data/Downloads/robotics/mrpt/mrpt/libs/vision/src/sift-hess/imgfeatures.c:10:
/usr/local/include/opencv2/highgui/highgui_c.h:139:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘:’ token
 CVAPI(cv::Rect)cvGetWindowImageRect(const char* name);
 ^
/media/jiapei/Data/Downloads/robotics/mrpt/mrpt/libs/vision/src/sift-hess/sift.c: In function ‘dominant_ori’:
/media/jiapei/Data/Downloads/robotics/mrpt/mrpt/libs/vision/src/sift-hess/sift.c:909:6: warning: variable ‘maxbin’ set but not used [-Wunused-but-set-variable]
  int maxbin, i;
      ^
libs/vision/CMakeFiles/mrpt-vision.dir/build.make:231: recipe for target 'libs/vision/CMakeFiles/mrpt-vision.dir/src/sift-hess/imgfeatures.c.o' failed
make[2]: *** [libs/vision/CMakeFiles/mrpt-vision.dir/src/sift-hess/imgfeatures.c.o] Error 1
make[2]: *** Waiting for unfinished jobs....
libs/vision/CMakeFiles/mrpt-vision.dir/build.make:244: recipe for target 'libs/vision/CMakeFiles/mrpt-vision.dir/src/sift-hess/sift.c.o' failed
make[2]: *** [libs/vision/CMakeFiles/mrpt-vision.dir/src/sift-hess/sift.c.o] Error 1
libs/vision/CMakeFiles/mrpt-vision.dir/build.make:257: recipe for target 'libs/vision/CMakeFiles/mrpt-vision.dir/src/sift-hess/utils.c.o' failed
make[2]: *** [libs/vision/CMakeFiles/mrpt-vision.dir/src/sift-hess/utils.c.o] Error 1
CMakeFiles/Makefile2:2400: recipe for target 'libs/vision/CMakeFiles/mrpt-vision.dir/all' failed
make[1]: *** [libs/vision/CMakeFiles/mrpt-vision.dir/all] Error 2
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2

Can anybody give some further suggestions ?
Thank you very much
Pei

@sergiomb2
Copy link
Contributor

sergiomb2 commented Mar 15, 2018

After update to libfreenect-0.5.7 it built well
php-facedetect also it built well after this commit [1], conclusion we need report it in VLC project

[1]
infusion/PHP-Facedetect@c717941

sjuxax added a commit to sjuxax/FFmpeg that referenced this issue Mar 18, 2018
Required for OpenCV 3.4.1 or later; strongly recommended for older
versions >= OpenCV 2. See opencv/opencv#10963.

This doesn't build yet -- the filter uses reserved C++ keywords
(`class`) and it needs additional casts.
@sjuxax
Copy link

sjuxax commented Mar 19, 2018

Raised on the ffmpeg-devel mailing list at http://ffmpeg.org/pipermail/ffmpeg-devel/2018-March/226872.html .

@tensor-flower
Copy link

Proposed fix by chris2553 worked for me. I'm 3.4.1-dev.

@chris2553
Copy link
Author

chris2553 commented Mar 27, 2018 via email

@StevenPuttemans
Copy link

Actually I arrived here when hitting similar problems re-installing the darknet framework (our own version). It works just fine by returning to 3.4.0, which given the limited stuff darknet uses from OpenCV works, but to me that shows that we changed something drastically in the switch from 3.4.0 to 3.4.1-dev. Any way of reverting those changes and identifying how we can circumvent this?

@AdamWill
Copy link

AdamWill commented Apr 5, 2018

@StevenPuttemans: the immediate change was c020a7b ; that code is not C compatible, it assumes namespace support. So you can revert things to the status of 3.4.0 by just patching an #if defined __cplusplus around that change, exactly as the initial report here says.

But given what @alalek wrote in this comment, it seems unwise to just do that and go on pretending that OpenCV is C compatible when it really isn't. Which is why no-one's really suggesting we push that change upstream any more, and instead look at changing what downstreams expect of OpenCV.

@NCBee
Copy link
Contributor

NCBee commented Apr 6, 2018

I beg to differ. Granted that OpenCV is first and foremost a C++ library, but why introduce a patch that breaks multiple downstream projects (in my case ffmpeg) just to prove a point? What is so hard about putting a __cplusplus guard around a "newly introduced functionality"? If we are not supporting C but keeping the legacy code, then why even touch the C headers that previously worked for downstream projects?

This issue cost me 4 hours to debug, whereas it would have cost someone 10 seconds to write the guard in the first place, or just leave the legacy code alone.

@StevenPuttemans
Copy link

StevenPuttemans commented Apr 6, 2018

@AdamWill I have to agree with @NCBee here. OpenCV has always ensured backwards compatibility. Although not actively ensuring a working C-API they have been keeping it alive just because so many downstream projects tend to use this API.

In my opinion it is a bad programming habbit to provide C++ - directives in C - headers. The convention is that if you provide a *.c or *.h file that it should be compiling perfectly fine using gcc. So either OpenCV should drop the deprecated C-headers (and in the process make more people angry), or follow general conventions.

@swills
Copy link

swills commented Apr 28, 2018

I also encountered this issue. Any chance of getting it resolved?

@swills
Copy link

swills commented Apr 30, 2018

This page:

https://docs.opencv.org/3.4.1/db/dfa/tutorial_transition_guide.html#tutorial_transition_hints_headers

Seems to imply the .h files should be usable with a non-C++ compiler.

@AdamWill
Copy link

Tutorials and docs are kind of notorious for not being kept entirely up to date. An explicit statement that this is not really the case any longer by one of the developers would seem to trump that.

hedgepigdaniel pushed a commit to hedgepigdaniel/ffmpeg-full that referenced this issue Jul 8, 2019
There is a know upstream ffmpeg compile error when enabling
libopencv. It should compile opencv code in C++ mode but it
is compiling in C mode. Disabling libopencv support while a
fix is not provided either by upstream ffmpeg or by opencv
repository package.

References:
-----------
http://trac.ffmpeg.org/ticket/7059
opencv/opencv#10963
https://bugs.archlinux.org/task/57811
archlinux-github pushed a commit to archlinux/aur that referenced this issue Nov 26, 2023
opencv support was disabled[1] a long time ago because ffmpeg failed
to build with it. opencv 3.x does not support C compilation mode[2]
anymore, and ffmpeg uses only C. There is no ffmpeg interest[3] in
compiling opencv in C++ mode, so opencv2 must be used here.

References
----------
[1] https://aur.archlinux.org/cgit/aur.git/commit/?h=ffmpeg-full&id=5d72306579c20bc36ff7c6ff1005b168e3b263de
[2] opencv/opencv#10963
[3] https://trac.ffmpeg.org/ticket/7059
archlinux-github pushed a commit to archlinux/aur that referenced this issue Nov 26, 2023
opencv support was disabled[1] a long time ago because ffmpeg failed
to build with it. opencv 3.x does not support C compilation mode[2]
anymore, and ffmpeg uses only C. There is no ffmpeg interest[3] in
compiling opencv in C++ mode, so opencv2 must be used here.

References
----------
[1] https://aur.archlinux.org/cgit/aur.git/commit/?h=ffmpeg-full-git&id=f9d589fa30dddc8318fff742a87b7927566b2a9e
[2] opencv/opencv#10963
[3] https://trac.ffmpeg.org/ticket/7059
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants