Qt6无法识别OpenCV(Windows端开发)
这段时间在Windows 10上进行Qt6的开发。结果在build过程中,出现了如下错误:
但实际上,我明明安装了OpenCV4.10.0, 并且也在CMakeLists.txt中加入了相关内容。
但是,注意自己的编译输出:
[1/5 1.4/sec] Automatic MOC and UIC for target RealTimeShowing
[2/5 0.7/sec] Building CXX object CMakeFiles/RealTimeShowing.dir/mainwindow.cpp.obj
[3/5 0.7/sec] Building CXX object CMakeFiles/RealTimeShowing.dir/main.cpp.obj
[4/5 0.9/sec] Building CXX object CMakeFiles/RealTimeShowing.dir/RealTimeShowing_autogen/mocs_compilation.cpp.obj
[5/5 1.1/sec] Linking CXX executable RealTimeShowing.exe
FAILED: RealTimeShowing.exe
C:\Windows\system32\cmd.exe /C "cd . && H:\Qt\Tools\mingw1310_64\bin\g++.exe -DQT_QML_DEBUG -g -mwindows CMakeFiles/RealTimeShowing.dir/RealTimeShowing_autogen/mocs_compilation.cpp.obj CMakeFiles/RealTimeShowing.dir/main.cpp.obj CMakeFiles/RealTimeShowing.dir/mainwindow.cpp.obj -o RealTimeShowing.exe -Wl,--out-implib,libRealTimeShowing.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -LH:/QtProgramming/RealTimeShowing/SYSTEM -LH:/OpenCV/opencv/build/x64/vc16/lib H:/Qt/6.9.0/mingw_64/lib/libQt6Widgets.a H:/Qt/6.9.0/mingw_64/lib/libQt6Gui.a H:/Qt/6.9.0/mingw_64/lib/libQt6Core.a -lmpr -luserenv -lmingw32 H:/Qt/6.9.0/mingw_64/lib/libQt6EntryPoint.a -lshell32 -ld3d11 -ldxgi -ldxguid -ld3d12 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
H:/Qt/Tools/mingw1310_64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/RealTimeShowing.dir/RealTimeShowing_autogen/mocs_compilation.cpp.obj: in function GetFrame::run()':
H:/QtProgramming/RealTimeShowing/GetFrame.h:29: undefined reference to cv::VideoCapture::VideoCapture(int, int)'
H:/Qt/Tools/mingw1310_64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: H:/QtProgramming/RealTimeShowing/GetFrame.h:31: undefined reference to cv::VideoCapture::isOpened() const'
H:/Qt/Tools/mingw1310_64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: H:/QtProgramming/RealTimeShowing/GetFrame.h:36: undefined reference to cv::Mat::Mat()'
H:/Qt/Tools/mingw1310_64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: H:/QtProgramming/RealTimeShowing/GetFrame.h:40: undefined reference to cv::VideoCapture::operator>>(cv::Mat&)'
H:/Qt/Tools/mingw1310_64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: H:/QtProgramming/RealTimeShowing/GetFrame.h:42: undefined reference to cv::Mat::empty() const'
H:/Qt/Tools/mingw1310_64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: H:/QtProgramming/RealTimeShowing/GetFrame.h:51: undefined reference to cv::VideoCapture::release()'
H:/Qt/Tools/mingw1310_64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: H:/QtProgramming/RealTimeShowing/GetFrame.h:52: undefined reference to cv::Mat::~Mat()'
H:/Qt/Tools/mingw1310_64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: H:/QtProgramming/RealTimeShowing/GetFrame.h:52: undefined reference to cv::VideoCapture::~VideoCapture()'
H:/Qt/Tools/mingw1310_64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: H:/QtProgramming/RealTimeShowing/GetFrame.h:52: undefined reference to cv::Mat::~Mat()'
H:/Qt/Tools/mingw1310_64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: H:/QtProgramming/RealTimeShowing/GetFrame.h:52: undefined reference to cv::VideoCapture::~VideoCapture()'
H:/Qt/Tools/mingw1310_64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/RealTimeShowing.dir/RealTimeShowing_autogen/mocs_compilation.cpp.obj: in function void std::__new_allocator<cv::Mat>::construct<cv::Mat, cv::Mat const&>(cv::Mat*, cv::Mat const&)':
H:/Qt/Tools/mingw1310_64/lib/gcc/x86_64-w64-mingw32/13.1.0/include/c++/bits/new_allocator.h:187: undefined reference to cv::Mat::Mat(cv::Mat const&)'
H:/Qt/Tools/mingw1310_64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: H:/Qt/Tools/mingw1310_64/lib/gcc/x86_64-w64-mingw32/13.1.0/include/c++/bits/new_allocator.h:187: undefined reference to cv::Mat::Mat(cv::Mat const&)'
H:/Qt/Tools/mingw1310_64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/RealTimeShowing.dir/main.cpp.obj: in function void std::_Destroy<cv::Mat>(cv::Mat*)':
H:/Qt/Tools/mingw1310_64/lib/gcc/x86_64-w64-mingw32/13.1.0/include/c++/bits/stl_construct.h:151: undefined reference to cv::Mat::~Mat()'
collect2.exe: error: ld returned 1 exit status
按照ChatGPT给出的建议,换成了MSVC 编译器就解决了问题
可见类似情况,关注下编译输出很有必要,可能问题就藏在其中。