Static Qt with OpenCV
-
wrote on 3 Jun 2024, 10:01 last edited by Pouriya 6 Mar 2024, 10:03
I've configured Qt 5.15.13 with below parameters:
configure.bat -static -release -platform win32-g++ -opensource -confirm-license -qt-zlib -qt-libpng -qt-webp -qt-libjpeg -qt-freetype -no-xcb -no-opengl -skip qtdoc -skip qtscxml -skip qtwebchannel -skip qtxmlpatterns -skip qt3d -skip qtcharts -skip qtdatavis3d -skip qtgamepad -skip qtlottie -skip qtmacextras -skip qtnetworkauth -skip qtpurchasing -skip qtquick3d -skip qtremoteobjects -skip qtscript -skip qtspeech -skip qtsvg -skip qtwayland -skip qtwebglplugin -skip qtwebview -skip webengine -skip qtvirtualkeyboard -make libs -nomake tools -nomake examples -nomake tests
and built it via mingw 11.2.0 x64 on Windows 10.
The build procedure finished with no error and qt installed successfullyI've also built two versions of opencv, one with
BUILD_SHARED_LIBS=OFF
and the other withBUILD_SHARED_LIBS=ON
parameter by means of the same compiler.When I add the dynamic build of opencv with qt, everything is fine, but when I use the static build of opencv I get these errors:
C:/Qt/Qt6/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\OpenCV490\opencv\release_static\lib\libopencv_videoio490.a(cap_images.cpp.obj):cap_images.cpp:(.text$_ZN2cv16CvCapture_Images9grabFrameEv+0x152): undefined reference to `cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)' C:/Qt/Qt6/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\OpenCV490\opencv\release_static\lib\libopencv_videoio490.a(cap_images.cpp.obj):cap_images.cpp:(.text$_ZN2cv20CvVideoWriter_Images4openEPKc+0x150): undefined reference to `cv::haveImageWriter(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' C:/Qt/Qt6/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\OpenCV490\opencv\release_static\lib\libopencv_videoio490.a(cap_images.cpp.obj):cap_images.cpp:(.text$_ZN2cv16CvCapture_Images4openERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x5a4): undefined reference to `cv::haveImageReader(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' C:/Qt/Qt6/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\OpenCV490\opencv\release_static\lib\libopencv_videoio490.a(cap_images.cpp.obj):cap_images.cpp:(.text$_ZN2cv16CvCapture_Images4openERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0xa5c): undefined reference to `cv::haveImageReader(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' C:/Qt/Qt6/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\OpenCV490\opencv\release_static\lib\libopencv_videoio490.a(cap_images.cpp.obj):cap_images.cpp:(.text$_ZN2cv20CvVideoWriter_Images10writeFrameEPK9_IplImage+0x152): undefined reference to `cv::imwrite(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)' C:/Qt/Qt6/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\OpenCV490\opencv\release_static\lib\libopencv_videoio490.a(cap_mjpeg_decoder.cpp.obj):cap_mjpeg_decoder.cpp:(.text$_ZN2cv17MotionJpegCapture13retrieveFrameEiRKNS_12_OutputArrayE+0x92): undefined reference to `cv::imdecode(cv::_InputArray const&, int)' collect2.exe: error: ld returned 1 exit status mingw32-make[1]: *** [Makefile.Release:74: release/videosender.exe] Error 1
This is the .pro file of the project:
Is there any solution for this problem?
-
I've configured Qt 5.15.13 with below parameters:
configure.bat -static -release -platform win32-g++ -opensource -confirm-license -qt-zlib -qt-libpng -qt-webp -qt-libjpeg -qt-freetype -no-xcb -no-opengl -skip qtdoc -skip qtscxml -skip qtwebchannel -skip qtxmlpatterns -skip qt3d -skip qtcharts -skip qtdatavis3d -skip qtgamepad -skip qtlottie -skip qtmacextras -skip qtnetworkauth -skip qtpurchasing -skip qtquick3d -skip qtremoteobjects -skip qtscript -skip qtspeech -skip qtsvg -skip qtwayland -skip qtwebglplugin -skip qtwebview -skip webengine -skip qtvirtualkeyboard -make libs -nomake tools -nomake examples -nomake tests
and built it via mingw 11.2.0 x64 on Windows 10.
The build procedure finished with no error and qt installed successfullyI've also built two versions of opencv, one with
BUILD_SHARED_LIBS=OFF
and the other withBUILD_SHARED_LIBS=ON
parameter by means of the same compiler.When I add the dynamic build of opencv with qt, everything is fine, but when I use the static build of opencv I get these errors:
C:/Qt/Qt6/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\OpenCV490\opencv\release_static\lib\libopencv_videoio490.a(cap_images.cpp.obj):cap_images.cpp:(.text$_ZN2cv16CvCapture_Images9grabFrameEv+0x152): undefined reference to `cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)' C:/Qt/Qt6/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\OpenCV490\opencv\release_static\lib\libopencv_videoio490.a(cap_images.cpp.obj):cap_images.cpp:(.text$_ZN2cv20CvVideoWriter_Images4openEPKc+0x150): undefined reference to `cv::haveImageWriter(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' C:/Qt/Qt6/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\OpenCV490\opencv\release_static\lib\libopencv_videoio490.a(cap_images.cpp.obj):cap_images.cpp:(.text$_ZN2cv16CvCapture_Images4openERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x5a4): undefined reference to `cv::haveImageReader(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' C:/Qt/Qt6/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\OpenCV490\opencv\release_static\lib\libopencv_videoio490.a(cap_images.cpp.obj):cap_images.cpp:(.text$_ZN2cv16CvCapture_Images4openERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0xa5c): undefined reference to `cv::haveImageReader(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' C:/Qt/Qt6/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\OpenCV490\opencv\release_static\lib\libopencv_videoio490.a(cap_images.cpp.obj):cap_images.cpp:(.text$_ZN2cv20CvVideoWriter_Images10writeFrameEPK9_IplImage+0x152): undefined reference to `cv::imwrite(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)' C:/Qt/Qt6/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\OpenCV490\opencv\release_static\lib\libopencv_videoio490.a(cap_mjpeg_decoder.cpp.obj):cap_mjpeg_decoder.cpp:(.text$_ZN2cv17MotionJpegCapture13retrieveFrameEiRKNS_12_OutputArrayE+0x92): undefined reference to `cv::imdecode(cv::_InputArray const&, int)' collect2.exe: error: ld returned 1 exit status mingw32-make[1]: *** [Makefile.Release:74: release/videosender.exe] Error 1
This is the .pro file of the project:
Is there any solution for this problem?
@Pouriya I think you need to fix the order in which you add the static libs. For example calib3d490 lib apparently depends on core490 lib.
1/2