Hey, I have an app I wrote in rust on linux that I wanted to use on my mac.
The porting effort was minimal, but the version of opencv I got via brew wasn’t linked to qt. On the linux side, I have a hot key that shows help. It’s a convenience.
When I went to open a PR to add qt to the list of libs it links to is where things got interesting.
Long story short I fell back to just getting the build out of git to work.
I have a working build, and the tests pass. I confirmed the link to qt is there with otool. But I’m a little lost as to why I had to massage the generated files.
I am not a cmake guy so a lot of this is just magic to me.
The error I ran into was a wall of text. Here’s a lightly formatted version:
cd /Users/mental/projects/opencv/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=\"/Users/mental/projects/opencv/build/modules/highgui\" \
-DQT_TESTCASE_SOURCEDIR=\"/Users/mental/projects/opencv/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/Users/mental/projects/opencv/build/modules/highgui \
-I/Users/mental/projects/opencv/modules/highgui -I/Users/mental/projects/opencv/build/3rdparty/zlib -I/Users/mental/projects/opencv/3rdparty/zlib \
-I/Users/mental/projects/opencv/build -I/opt/homebrew/lib/QtDBus.framework/Headers -iframework /opt/homebrew/lib \
-I/Users/mental/projects/opencv/modules/highgui/include -I/Users/mental/projects/opencv/modules/core/include \
-I/Users/mental/projects/opencv/modules/imgproc/include -I/Users/mental/projects/opencv/modules/imgcodecs/include \
-I/Users/mental/projects/opencv/modules/videoio/include \
-F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks \
-isystem /opt/homebrew/lib/QtCore.framework/Headers -isystem /opt/homebrew/lib/QtGui.framework/Headers -isystem /opt/homebrew/lib/QtWidgets.framework/Headers \
-isystem /opt/homebrew/lib/QtTest.framework/Headers -isystem /opt/homebrew/lib/QtConcurrent.framework/Headers \
-isystem /opt/homebrew/lib/QtOpenGLWidgets.framework/Headers -isystem /opt/homebrew/lib/QtOpenGL.framework/Headers \
-isystem /opt/homebrew/include/eigen3 -isystem /opt/homebrew/share/qt/mkspecs/macx-clang -isystem /opt/homebrew/include \
-fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations \
-Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor \
-Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections \
-fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -Wno-deprecated-copy -Wno-deprecated-declarations -O3 -DNDEBUG -DNDEBUG \
-std=c++17 -arch arm64 -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 /Users/mental/projects/opencv/modules/highgui/src/backend.cpp
So that’s not valid for the shell. And I think it’s extra stuff being generated likely due to a bug in a place I don’t even know to look.
So, I took it on myself to just cleanup the flags.make files. This issue only happened in the highgui module. Which makes sense since that’s where imgshow and friends live and use qt behind the scenes.
The change was this:
diff --git a/CMakeFiles/opencv_highgui.dir/flags.make b/CMakeFiles/opencv_highgui.dir/flags.make
index df19c8b..a3a3264 100644
--- a/CMakeFiles/opencv_highgui.dir/flags.make
+++ b/CMakeFiles/opencv_highgui.dir/flags.make
@@ -6,7 +6,7 @@ CXX_DEFINES = -DCVAPI_EXPORTS -DENABLE_PLUGINS -DHAVE_QT -DHAVE_QT6 -DHAVE_QT_OP
CXX_INCLUDES = -I/Users/mental/projects/opencv/build/modules/highgui -I/Users/mental/projects/opencv/modules/highgui -I/Users/mental/projects/opencv/build/3rdparty/zlib -I/Users/mental/projects/opencv/3rdparty/zlib -I/Users/mental/projects/opencv/build -I/opt/homebrew/lib/QtDBus.framework/Headers -iframework /opt/homebrew/lib -I/Users/mental/projects/opencv/modules/highgui/include -I/Users/mental/projects/opencv/modules/core/include -I/Users/mental/projects/opencv/modules/imgproc/include -I/Users/mental/projects/opencv/modules/imgcodecs/include -I/Users/mental/projects/opencv/modules/videoio/include -F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks -isystem /opt/homebrew/lib/QtCore.framework/Headers -isystem /opt/homebrew/lib/QtGui.framework/Headers -isystem /opt/homebrew/lib/QtWidgets.framework/Headers -isystem /opt/homebrew/lib/QtTest.framework/Headers -isystem /opt/homebrew/lib/QtConcurrent.framework/Headers -isystem /opt/homebrew/lib/QtOpenGLWidgets.framework/Headers -isystem /opt/homebrew/lib/QtOpenGL.framework/Headers -isystem /opt/homebrew/include/eigen3 -isystem /opt/homebrew/share/qt/mkspecs/macx-clang -isystem /opt/homebrew/include
-CXX_FLAGSarm64 = -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -Wno-deprecated-copy -Wno-deprecated-declarations -O3 -DNDEBUG -DNDEBUG -std=c++17 -arch arm64 -fPIC $<$<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>">
+CXX_FLAGSarm64 = -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -Wno-deprecated-copy -Wno-deprecated-declarations -O3 -DNDEBUG -DNDEBUG -std=c++17 -arch arm64 -fPIC
-CXX_FLAGS = -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -Wno-deprecated-copy -Wno-deprecated-declarations -O3 -DNDEBUG -DNDEBUG -std=c++17 -arch arm64 -fPIC $<$<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>">
+CXX_FLAGS = -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -Wno-deprecated-copy -Wno-deprecated-declarations -O3 -DNDEBUG -DNDEBUG -std=c++17 -arch arm64 -fPIC
diff --git a/CMakeFiles/opencv_test_highgui.dir/flags.make b/CMakeFiles/opencv_test_highgui.dir/flags.make
index 2e0816d..d0357ca 100644
--- a/CMakeFiles/opencv_test_highgui.dir/flags.make
+++ b/CMakeFiles/opencv_test_highgui.dir/flags.make
@@ -6,7 +6,7 @@ CXX_DEFINES = -DENABLE_PLUGINS -DHAVE_QT -DHAVE_QT6 -DHAVE_QT_OPENGL -DHAVE_WEBP
CXX_INCLUDES = -I/Users/mental/projects/opencv/build/modules/highgui -I/Users/mental/projects/opencv/modules/highgui -I/Users/mental/projects/opencv/build/3rdparty/zlib -I/Users/mental/projects/opencv/3rdparty/zlib -I/Users/mental/projects/opencv/build -I/opt/homebrew/lib/QtCore.framework/Headers -F/opt/homebrew/lib -I/opt/homebrew/lib/QtGui.framework/Headers -I/opt/homebrew/lib/QtDBus.framework/Headers -I/opt/homebrew/lib/QtWidgets.framework/Headers -I/opt/homebrew/lib/QtTest.framework/Headers -I/opt/homebrew/lib/QtConcurrent.framework/Headers -I/opt/homebrew/lib/QtOpenGLWidgets.framework/Headers -I/opt/homebrew/lib/QtOpenGL.framework/Headers -I/Users/mental/projects/opencv/modules/ts/include -I/Users/mental/projects/opencv/modules/highgui/include -I/Users/mental/projects/opencv/modules/imgcodecs/include -I/Users/mental/projects/opencv/modules/videoio/include -I/Users/mental/projects/opencv/modules/core/include -I/Users/mental/projects/opencv/modules/imgproc/include -isystem /opt/homebrew/include/eigen3
-CXX_FLAGSarm64 = -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -Wno-deprecated-copy -Wno-deprecated-declarations -O3 -DNDEBUG -DNDEBUG -std=c++11 -arch arm64 -fPIE $<$<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>">
+CXX_FLAGSarm64 = -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -Wno-deprecated-copy -Wno-deprecated-declarations -O3 -DNDEBUG -DNDEBUG -std=c++11 -arch arm64 -fPIE
-CXX_FLAGS = -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -Wno-deprecated-copy -Wno-deprecated-declarations -O3 -DNDEBUG -DNDEBUG -std=c++11 -arch arm64 -fPIE $<$<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>">
+CXX_FLAGS = -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -Wno-deprecated-copy -Wno-deprecated-declarations -O3 -DNDEBUG -DNDEBUG -std=c++11 -arch arm64 -fPIE
If this helps someone else, great. Should I just open an issue on github about this?
At this point since I can’t open a PR for brew to add qt, I’ll probably locally manage an opencv runtime since it doesn’t compile OOTB and brew really wants it to “just work”.
Oh… how I built it. Grabbed the opencv and opencv_contrib repos off github. Made sure both had the 4.11.0 tag checked out and did this:
if [ -d build ]; then
rm -rf build
fi
mkdir build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-DCMAKE_INSTALL_PREFIX=${HOME}/QtOpenCV \
-D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D BUILD_opencv_python2=OFF \
-D BUILD_opencv_python3=ON \
-D WITH_QT=ON \
-D OPENCV_ENABLE_NONFREE=ON \
-D WITH_GSTREAMER=ON \
-D WITH_OPENGL=ON \
-D BUILD_EXAMPLES=ON -S . -B ./build