opencv icon indicating copy to clipboard operation
opencv copied to clipboard

Fails to build with Qt 6.9

Open badshah400 opened this issue 8 months ago • 2 comments

System Information

OpenCV version 4.11.0 GCC 14.2.1 Qt version 6.9.0

Platform: openSUSE Tumbleweed (Linux) Archs: x86_64, aarch64

Detailed description

OpenCV version 4.11.0 fails to build with Qt6 version 6.9. When using ninja as the builder, cmake fails at the configure stage with:

ninja: error: build.ninja:13215: bad $-escape (literal $ must be written as $$)

A full log file corresponding to this build is attached: _log.gz.

Alternatively, when using make, the configure succeeds, but the build fails down the line nonetheless:

[  405s] [ 27%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/backend.cpp.o
[  405s] cd /home/abuild/rpmbuild/BUILD/opencv-qt6-4.11.0-build/opencv-4.11.0/build/modules/highgui && /usr/bin/c++ -DCVAPI_EXPORTS -DENABLE_PLUGINS -DHAVE_QT -DHAVE_QT6 -DHAVE_QT_OPENGL -DHAVE_WEBP -DQT_CONCURRENT_LIB -DQT_CORE_LIB -DQT_DBUS_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DQT_OPENGLWIDGETS_LIB -DQT_OPENGL_LIB -DQT_TESTCASE_BUILDDIR=\"/home/abuild/rpmbuild/BUILD/opencv-qt6-4.11.0-build/opencv-4.11.0/build/modules/highgui\" -DQT_TESTCASE_SOURCEDIR=\"/home/abuild/rpmbuild/BUILD/opencv-qt6-4.11.0-build/opencv-4.11.0/modules/highgui\" -DQT_TESTLIB_LIB -DQT_WIDGETS_LIB -D_USE_MATH_DEFINES -D__OPENCV_BUILD=1 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/abuild/rpmbuild/BUILD/opencv-qt6-4.11.0-build/opencv-4.11.0/build/modules/highgui -I/home/abuild/rpmbuild/BUILD/opencv-qt6-4.11.0-build/opencv-4.11.0/modules/highgui -I/home/abuild/rpmbuild/BUILD/opencv-qt6-4.11.0-build/opencv-4.11.0/build -I/usr/include/qt6/QtDBus -I/home/abuild/rpmbuild/BUILD/opencv-qt6-4.11.0-build/opencv-4.11.0/modules/highgui/include -I/home/abuild/rpmbuild/BUILD/opencv-qt6-4.11.0-build/opencv-4.11.0/modules/core/include -I/home/abuild/rpmbuild/BUILD/opencv-qt6-4.11.0-build/opencv-4.11.0/modules/imgproc/include -I/home/abuild/rpmbuild/BUILD/opencv-qt6-4.11.0-build/opencv-4.11.0/modules/imgcodecs/include -I/home/abuild/rpmbuild/BUILD/opencv-qt6-4.11.0-build/opencv-4.11.0/modules/videoio/include -isystem /usr/include/openblas -isystem /usr/include/qt6/QtCore -isystem /usr/include/qt6 -isystem /usr/include/qt6/QtGui -isystem /usr/include/qt6/QtWidgets -isystem /usr/include/qt6/QtTest -isystem /usr/include/qt6/QtConcurrent -isystem /usr/include/qt6/QtOpenGLWidgets -isystem /usr/include/qt6/QtOpenGL -isystem /usr/include/eigen3 -isystem /usr/lib64/qt6/mkspecs/linux-g++ -O2 -Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -flto=auto -g   -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -Wno-deprecated-declarations -O3 -DNDEBUG  -DNDEBUG -std=c++17 -fPIC   modules/highgui/CMakeFiles/opencv_highgui.dir/compiler_depend.tsmodules/highgui/CMakeFiles/opencv_highgui.dir/compiler_depend.tsNOT:modules/highgui/CMakeFiles/opencv_highgui.dir/compiler_depend.tsBOOL:modules/highgui/CMakeFiles/opencv_highgui.dir/compiler_depend.tsTARGET_PROPERTY:QT_SKIP_DEFAULT_TESTCASE_DIRS>>>:QT_TESTCASE_BUILDDIR="modules/highgui/CMakeFiles/opencv_highgui.dir/compiler_depend.tsIF:modules/highgui/CMakeFiles/opencv_highgui.dir/compiler_depend.tsBOOL:modules/highgui/CMakeFiles/opencv_highgui.dir/compiler_depend.tsTARGET_PROPERTY:QT_TESTCASE_BUILDDIR>>,modules/highgui/CMakeFiles/opencv_highgui.dir/compiler_depend.tsTARGET_PROPERTY:QT_TESTCASE_BUILDDIR>,modules/highgui/CMakeFiles/opencv_highgui.dir/compiler_depend.tsTARGET_PROPERTY:BINARY_DIR>>"modules/highgui/CMakeFiles/opencv_highgui.dir/compiler_depend.tsSEMICOLON>QT_TESTCASE_SOURCEDIR="modules/highgui/CMakeFiles/opencv_highgui.dir/compiler_depend.tsTARGET_PROPERTY:SOURCE_DIR>"> -MD -MT modules/highgui/CMakeFiles/opencv_highgui.dir/src/backend.cpp.o -MF CMakeFiles/opencv_highgui.dir/src/backend.cpp.o.d -o CMakeFiles/opencv_highgui.dir/src/backend.cpp.o -c /home/abuild/rpmbuild/BUILD/opencv-qt6-4.11.0-build/opencv-4.11.0/modules/highgui/src/backend.cpp
[  405s] /bin/sh: -c: line 1: syntax error near unexpected token `>'
[  405s] /bin/sh: -c: line 1: `cd /home/abuild/rpmbuild/BUILD/opencv-qt6-4.11.0-build/opencv-4.11.0/build/modules/highgui && /usr/bin/c++ -DCVAPI_EXPORTS -DENABLE_PLUGINS -DHAVE_QT -DHAVE_QT6 -DHAVE_QT_OPENGL -DHAVE_WEBP -DQT_CONCURRENT_LIB -DQT_CORE_LIB -DQT_DBUS_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DQT_OPENGLWIDGETS_LIB -DQT_OPENGL_LIB -DQT_TESTCASE_BUILDDIR=\"/home/abuild/rpmbuild/BUILD/opencv-qt6-4.11.0-build/opencv-4.11.0/build/modules/highgui\" -DQT_TESTCASE_SOURCEDIR=\"/home/abuild/rpmbuild/BUILD/opencv-qt6-4.11.0-build/opencv-4.11.0/modules/highgui\" -DQT_TESTLIB_LIB -DQT_WIDGETS_LIB -D_USE_MATH_DEFINES -D__OPENCV_BUILD=1 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/abuild/rpmbuild/BUILD/opencv-qt6-4.11.0-build/opencv-4.11.0/build/modules/highgui -I/home/abuild/rpmbuild/BUILD/opencv-qt6-4.11.0-build/opencv-4.11.0/modules/highgui -I/home/abuild/rpmbuild/BUILD/opencv-qt6-4.11.0-build/opencv-4.11.0/build -I/usr/include/qt6/QtDBus -I/home/abuild/rpmbuild/BUILD/opencv-qt6-4.11.0-build/opencv-4.11.0/modules/highgui/include -I/home/abuild/rpmbuild/BUILD/opencv-qt6-4.11.0-build/opencv-4.11.0/modules/core/include -I/home/abuild/rpmbuild/BUILD/opencv-qt6-4.11.0-build/opencv-4.11.0/modules/imgproc/include -I/home/abuild/rpmbuild/BUILD/opencv-qt6-4.11.0-build/opencv-4.11.0/modules/imgcodecs/include -I/home/abuild/rpmbuild/BUILD/opencv-qt6-4.11.0-build/opencv-4.11.0/modules/videoio/include -isystem /usr/include/openblas -isystem /usr/include/qt6/QtCore -isystem /usr/include/qt6 -isystem /usr/include/qt6/QtGui -isystem /usr/include/qt6/QtWidgets -isystem /usr/include/qt6/QtTest -isystem /usr/include/qt6/QtConcurrent -isystem /usr/include/qt6/QtOpenGLWidgets -isystem /usr/include/qt6/QtOpenGL -isystem /usr/include/eigen3 -isystem /usr/lib64/qt6/mkspecs/linux-g++ -O2 -Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -flto=auto -g   -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -Wno-deprecated-declarations -O3 -DNDEBUG  -DNDEBUG -std=c++17 -fPIC   modules/highgui/CMakeFiles/opencv_highgui.dir/compiler_depend.tsmodules/highgui/CMakeFiles/opencv_highgui.dir/compiler_depend.tsNOT:modules/highgui/CMakeFiles/opencv_highgui.dir/compiler_depend.tsBOOL:modules/highgui/CMakeFiles/opencv_highgui.dir/compiler_depend.tsTARGET_PROPERTY:QT_SKIP_DEFAULT_TESTCASE_DIRS>>>:QT_TESTCASE_BUILDDIR="modules/highgui/CMakeFiles/opencv_highgui.dir/compiler_depend.tsIF:modules/highgui/CMakeFiles/opencv_highgui.dir/compiler_depend.tsBOOL:modules/highgui/CMakeFiles/opencv_highgui.dir/compiler_depend.tsTARGET_PROPERTY:QT_TESTCASE_BUILDDIR>>,modules/highgui/CMakeFiles/opencv_highgui.dir/compiler_depend.tsTARGET_PROPERTY:QT_TESTCASE_BUILDDIR>,modules/highgui/CMakeFiles/opencv_highgui.dir/compiler_depend.tsTARGET_PROPERTY:BINARY_DIR>>"modules/highgui/CMakeFiles/opencv_highgui.dir/compiler_depend.tsSEMICOLON>QT_TESTCASE_SOURCEDIR="modules/highgui/CMakeFiles/opencv_highgui.dir/compiler_depend.tsTARGET_PROPERTY:SOURCE_DIR>"> -MD -MT modules/highgui/CMakeFiles/opencv_highgui.dir/src/backend.cpp.o -MF CMakeFiles/opencv_highgui.dir/src/backend.cpp.o.d -o CMakeFiles/opencv_highgui.dir/src/backend.cpp.o -c /home/abuild/rpmbuild/BUILD/opencv-qt6-4.11.0-build/opencv-4.11.0/modules/highgui/src/backend.cpp'
[  405s] make[2]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/build.make:103: modules/highgui/CMakeFiles/opencv_highgui.dir/src/backend.cpp.o] Error 2

Steps to reproduce

Try compiling on a system with Qt version 6.9+ with highgui module enabled. The command used to configure is as follows (this is from an attempt to build the module with Qt6 as part of openSUSE Tumbleweed's RPM packages):

/usr/bin/cmake /home/abuild/rpmbuild/BUILD/opencv-qt6-4.11.0-build/opencv-4.11.0/. -GNinja -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_INSTALL_BINDIR:PATH=bin -DCMAKE_INSTALL_SBINDIR:PATH=sbin -DCMAKE_INSTALL_LIBEXECDIR:PATH=libexec -DCMAKE_INSTALL_SYSCONFDIR:PATH=etc -DCMAKE_INSTALL_SHAREDSTATEDIR:PATH=/var/lib -DCMAKE_INSTALL_LOCALSTATEDIR:PATH=var -DCMAKE_INSTALL_RUNSTATEDIR:PATH=run -DCMAKE_INSTALL_LIBDIR:PATH=lib64 -DCMAKE_INSTALL_INCLUDEDIR:PATH=include -DCMAKE_INSTALL_DATAROOTDIR:PATH=share -DCMAKE_INSTALL_DOCDIR:PATH=share/doc/packages/opencv-qt6 -DCMAKE_INSTALL_MANDIR:PATH=share/man -DCMAKE_INSTALL_INFODIR:PATH=share/info -DINCLUDE_INSTALL_DIR:PATH=/usr/include -DLIB_INSTALL_DIR:PATH=/usr/lib64 -DSYSCONF_INSTALL_DIR:PATH=/etc -DSHARE_INSTALL_PREFIX:PATH=/usr/share -DCMAKE_BUILD_TYPE=RelWithDebInfo '-DCMAKE_C_FLAGS=-O2 -Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -flto=auto -g' '-DCMAKE_CXX_FLAGS=-O2 -Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -flto=auto -g' '-DCMAKE_Fortran_FLAGS=-O2 -Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -flto=auto -g' '-DCMAKE_EXE_LINKER_FLAGS=-flto=auto -Wl,--as-needed -Wl,--no-undefined -Wl,-z,now' '-DCMAKE_MODULE_LINKER_FLAGS=-flto=auto -Wl,--as-needed' '-DCMAKE_SHARED_LINKER_FLAGS=-flto=auto -Wl,--as-needed -Wl,--no-undefined -Wl,-z,now' -DLIB_SUFFIX=64 -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DBUILD_SHARED_LIBS:BOOL=ON -DBUILD_STATIC_LIBS:BOOL=OFF -DCMAKE_COLOR_MAKEFILE:BOOL=OFF -DCMAKE_INSTALL_DO_STRIP:BOOL=OFF -DCMAKE_MODULES_INSTALL_DIR=/usr/lib64/cmake/opencv-qt6 -DCMAKE_BUILD_TYPE=Release -DBUILD_WITH_DEBUG_INFO=ON -DBUILD_TESTS:BOOL=OFF -DOPENCV_INCLUDE_INSTALL_PATH=/usr/include -DOPENCV_LICENSES_INSTALL_PATH=/usr/share/licenses/opencv-qt6 -DOPENCV_GENERATE_PKGCONFIG=ON -DINSTALL_C_EXAMPLES=ON -DINSTALL_PYTHON_EXAMPLES=ON -DENABLE_OMIT_FRAME_POINTER=ON -DWITH_QT=ON -DBUILD_opencv_highgui=ON -DWITH_OPENGL=ON -DOpenGL_GL_PREFERENCE:STRING=GLVND -DWITH_UNICAP=ON -DWITH_XINE=ON -DWITH_IPP=OFF -DWITH_TBB=ON -Dade_DIR:PATH=/usr/share/ade -DCPU_BASELINE=SSE2 -DCPU_DISPATCH=SSE3,SSE4_1,SSE4_2,FP16,FMA3,AVX,AVX2,AVX512_ICL -DBUILD_opencv_python3=OFF -DPYTHON_DEFAULT_EXECUTABLE=/usr/bin/python3 -DOPENCV_DOWNLOAD_TRIES_LIST:STRING= -DWITH_JASPER=OFF

Issue submission checklist

  • [x] I report the issue, it's not a question
  • [x] I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • [x] I updated to the latest OpenCV version and the issue is still there
  • [ ] There is reproducer code and related data files (videos, images, onnx, etc)

badshah400 avatar Apr 11 '25 07:04 badshah400

See also https://bugreports.qt.io/browse/QTBUG-134774

badshah400 avatar Apr 11 '25 07:04 badshah400

This seems to make it work, but no idea if this is the fix:

---
 modules/highgui/CMakeLists.txt |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: opencv-4.11.0/modules/highgui/CMakeLists.txt
===================================================================
--- opencv-4.11.0.orig/modules/highgui/CMakeLists.txt
+++ opencv-4.11.0/modules/highgui/CMakeLists.txt
@@ -125,7 +125,7 @@ elseif(HAVE_QT)
     endif()
 
     foreach(dt_dep ${qt_deps})
-      add_definitions(${Qt${QT_VERSION_MAJOR}${dt_dep}_DEFINITIONS})
+      link_libraries(${Qt${QT_VERSION_MAJOR}${dt_dep}})
       include_directories(${Qt${QT_VERSION_MAJOR}${dt_dep}_INCLUDE_DIRS})
       list(APPEND HIGHGUI_LIBRARIES ${Qt${QT_VERSION_MAJOR}${dt_dep}_LIBRARIES})
     endforeach()

badshah400 avatar Apr 11 '25 18:04 badshah400

We're seeing the same in Fedora. The patch from @badshah400 fixes the build for us too. Thanks a lot.

AdamWill avatar Jul 08 '25 23:07 AdamWill

I confirm that @badshah400's patch solved the problem for me too. Can it be added to the master?

thewoz avatar Oct 15 '25 14:10 thewoz

@badshah400 could you make a formal pull request for this project to merge your patch ? Thanks in advance.

kwizart avatar Oct 15 '25 15:10 kwizart

@kwizart done, thanks for the ping

badshah400 avatar Oct 15 '25 16:10 badshah400