-- Configuring done (12.3s) CMake Error: Running '/usr/bin/ninja' '-C' '/var/tmp/portage/media-libs/opencv-4.10.0/work/opencv-4.10.0_build-abi_x86_64.amd64' '-t' 'recompact' failed with: ninja: error: build.ninja:19111: bad $-escape (literal $ must be written as $$) It's also broken when forcing emake to be used instead of Ninja with a package.env file like this: /etc/portage/env/opencv.conf CMAKE_MAKEFILE_GENERATOR="emake" This fails with a different error: /bin/sh: -c: line 1: syntax error near unexpected token `>' /bin/sh: -c: line 1: `cd /var/tmp/portage/media-libs/opencv-4.10.0/work/opencv-4.10.0_build-abi_x86_64.amd64/modules/highgui && /usr/bin/x86_64-pc-linux-gnu-g++ -DCVAPI_EXPORTS -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=\"/var/tmp/portage/media-libs/opencv-4.10.0/work/opencv-4.10.0_build-abi_x86_64.amd64/modules/highgui\" -DQT_TESTCASE_SOURCEDIR=\"/var/tmp/portage/media-libs/opencv-4.10.0/work/opencv-4.10.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/var/tmp/portage/media-libs/opencv-4.10.0/work/opencv-4.10.0_build-abi_x86_64.amd64/modules/highgui -I/var/tmp/portage/media-libs/opencv-4.10.0/work/opencv-4.10.0/modules/highgui -I/usr/include/qt6/QtDBus -I/var/tmp/portage/media-libs/opencv-4.10.0/work/opencv-4.10.0/modules/highgui/include -I/var/tmp/portage/media-libs/opencv-4.10.0/work/opencv-4.10.0/modules/core/include -I/var/tmp/portage/media-libs/opencv-4.10.0/work/opencv-4.10.0/modules/imgproc/include -I/var/tmp/portage/media-libs/opencv-4.10.0/work/opencv-4.10.0/modules/imgcodecs/include -I/var/tmp/portage/media-libs/opencv-4.10.0/work/opencv-4.10.0/modules/videoio/include -isystem /var/tmp/portage/media-libs/opencv-4.10.0/work/opencv-4.10.0_build-abi_x86_64.amd64 -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++ -O3 -march=native -fasynchronous-unwind-tables -pipe -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 -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -mssse3 -msse4.1 -mpopcnt -msse4.2 -mf16c -mfma -mavx -mavx2 -fvisibility=hidden -fvisibility-inlines-hidden -fopenmp -Wno-deprecated-declarations -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>"> -fPIC -MD -MT modules/highgui/CMakeFiles/opencv_highgui.dir/src/window.cpp.o -MF CMakeFiles/opencv_highgui.dir/src/window.cpp.o.d -o CMakeFiles/opencv_highgui.dir/src/window.cpp.o -c /var/tmp/portage/media-libs/opencv-4.10.0/work/opencv-4.10.0/modules/highgui/src/window.cpp' /bin/sh: -c: line 1: syntax error near unexpected token `>' /bin/sh: -c: line 1: `cd /var/tmp/portage/media-libs/opencv-4.10.0/work/opencv-4.10.0_build-abi_x86_64.amd64/modules/highgui && /usr/bin/x86_64-pc-linux-gnu-g++ -DCVAPI_EXPORTS -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=\"/var/tmp/portage/media-libs/opencv-4.10.0/work/opencv-4.10.0_build-abi_x86_64.amd64/modules/highgui\" -DQT_TESTCASE_SOURCEDIR=\"/var/tmp/portage/media-libs/opencv-4.10.0/work/opencv-4.10.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/var/tmp/portage/media-libs/opencv-4.10.0/work/opencv-4.10.0_build-abi_x86_64.amd64/modules/highgui -I/var/tmp/portage/media-libs/opencv-4.10.0/work/opencv-4.10.0/modules/highgui -I/usr/include/qt6/QtDBus -I/var/tmp/portage/media-libs/opencv-4.10.0/work/opencv-4.10.0/modules/highgui/include -I/var/tmp/portage/media-libs/opencv-4.10.0/work/opencv-4.10.0/modules/core/include -I/var/tmp/portage/media-libs/opencv-4.10.0/work/opencv-4.10.0/modules/imgproc/include -I/var/tmp/portage/media-libs/opencv-4.10.0/work/opencv-4.10.0/modules/imgcodecs/include -I/var/tmp/portage/media-libs/opencv-4.10.0/work/opencv-4.10.0/modules/videoio/include -isystem /var/tmp/portage/media-libs/opencv-4.10.0/work/opencv-4.10.0_build-abi_x86_64.amd64 -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++ -O3 -march=native -fasynchronous-unwind-tables -pipe -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 -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -mssse3 -msse4.1 -mpopcnt -msse4.2 -mf16c -mfma -mavx -mavx2 -fvisibility=hidden -fvisibility-inlines-hidden -fopenmp -Wno-deprecated-declarations -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>"> -fPIC -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 /var/tmp/portage/media-libs/opencv-4.10.0/work/opencv-4.10.0/modules/highgui/src/backend.cpp' Something is likely wrong with one of the CMake files used by Qt somewhere as Opencv cannot be built with qt6 enabled, it builds fine with it disabled (USE="-qt6 -opengl"): $ qlist -ICv dev-qt dev-qt/qtbase-6.9.0 dev-qt/qttools-6.9.0 dev-qt/qttranslations-6.9.0 For reference, the versions of CMake and Ninja are as follows: $ cmake --version cmake version 3.31.6 $ ninja --version 1.12.1 Reproducible: Always $ emerge --info ================================================================= Package Settings ================================================================= media-libs/opencv-4.10.0::gentoo was built with the following: USE="avif contrib contribdnn eigen features2d ffmpeg jpeg opencl opengl openmp png qt6 tesseract truetype vaapi webp -atlas -contribcvv -contribfreetype -contribhdf (-contribovis) -contribsfm -contribxfeatures2d -cuda -cudnn -debug -dnnsamples -doc -examples -gdal -gflags -glog -gphoto2 -gstreamer -gtk3 -ieee1394 -jasper -java -jpeg2k -lapack -mkl -non-free -opencvapps -openexr -python -quirc -tbb -test -testprograms -tiff -v4l -vtk -xine" CPU_FLAGS_X86="avx avx2 f16c fma3 popcnt sse sse2 sse3 sse4_1 sse4_2 ssse3 -avx512_4fmaps -avx512_4vnniw -avx512_bitalg -avx512_vbmi2 -avx512_vnni -avx512_vpopcntdq -avx512bw -avx512cd -avx512dq -avx512er -avx512f -avx512ifma -avx512pf -avx512vbmi -avx512vl" PYTHON_TARGETS="python3_10 python3_11 python3_12 python3_13" VIDEO_CARDS="-intel" CFLAGS="-O3 -march=native -fasynchronous-unwind-tables -pipe" CXXFLAGS="-O3 -march=native -fasynchronous-unwind-tables -pipe" FEATURES="assume-digests binpkg-docompress binpkg-dostrip binpkg-logs buildpkg buildpkg-live candy config-protect-if-modified distlocks ebuild-locks fixlafiles ipc-sandbox merge-sync merge-wait multilib-strict network-sandbox news parallel-fetch pkgdir-index-trusted preserve-libs protect-owned qa-unresolved-soname-deps sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
Haven't had time to really look at this, but think issue could be in qtbase unless opencv is doing something weird (why is this only coming up with opencv?), the broken bit that got included is from /usr/lib64/cmake/Qt6Test/Qt6TestTargets.cmake Qt 6.8.3 had: INTERFACE_COMPILE_DEFINITIONS "QT_TESTLIB_LIB;QT_TESTCASE_BUILDDIR=\"\$<IF:\$<BOOL:\$<TARGET_PROPERTY:QT_TESTCASE_BUILDDIR>>,\$<TARGET_PROPERTY:QT_TESTCASE_BUILDDIR>,\$<TARGET_PROPERTY:BINARY_DIR>>\";QT_TESTCASE_SOURCEDIR=\"\$<TARGET_PROPERTY:SOURCE_DIR>\"" Qt 6.9.0 has: INTERFACE_COMPILE_DEFINITIONS "QT_TESTLIB_LIB;\$<\$<NOT:\$<BOOL:\$<TARGET_PROPERTY:QT_SKIP_DEFAULT_TESTCASE_DIRS>>>:QT_TESTCASE_BUILDDIR=\"\$<IF:\$<BOOL:\$<TARGET_PROPERTY:QT_TESTCASE_BUILDDIR>>,\$<TARGET_PROPERTY:QT_TESTCASE_BUILDDIR>,\$<TARGET_PROPERTY:BINARY_DIR>>\"\$<SEMICOLON>QT_TESTCASE_SOURCEDIR=\"\$<TARGET_PROPERTY:SOURCE_DIR>\">" Maybe there's some syntax issue in there, not that I'm big on cmake. Likely related to [1] which been there since 6.9.0-beta1 [1] https://github.com/qt/qtbase/commit/ecf8843720a0240dc310c169a4dd605f8f0cab45
Ah, found the Qt bug, was filed two days after 6.9.0-rc but unfortunately had no activity since.
(In reply to Ionen Wolkens from comment #2) > Ah, found the Qt bug, was filed two days after 6.9.0-rc but unfortunately > had no activity since. ... but reading it, points to being an opencv issue > So ideally, opencv should fix its build system to use target_compile_definitions. > For now, i'm leaning towards closing this as invalid.
Created attachment 925609 [details, diff] media-libs/opencv unconfirmed fix patch
The linked opencv ticket has a patch that I was able to use to successfully build this. It is an unconfirmed fix but if you are also here because just want something to move on with things, it worked for me.
I can confirm that the comment in opencv bug tracker can fix this. Since I'm big on cmake, the fix is real.