V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
GhostRider
V2EX  ›  Qt

QT 编译 opencv 源码报错怎么搞??

  •  
  •   GhostRider · 2018-12-04 16:24:35 +08:00 · 5776 次点击
    这是一个创建于 2215 天前的主题,其中的信息可能已经有所发展或是发生改变。

    楼主主要是想编译 opecv 库在 QT 里面使用,但是编译遇到问题,看过各种帖子还是有问题,敢请大佬指教。配置如下:

    • 平台 win10 64 位
    • QT5.8 32 位(QT Creater4.21 + MinGW5.30 32 位 + Cmake 3.81 64 位)
    • Cmake 选项按参考的这篇博客

    使用 QT 编译之后编译到 95%的时候链接出现问题如下:

    ...
    [ 95%] Linking CXX shared library ..\..\bin\libopencv_world330.dll
    CMakeFiles\opencv_world.dir/objects.a(parallel_pthreads.cpp.obj): In function `sscanf':
    D:/Qt/Qt5.8.0/Tools/mingw530_32/i686-w64-mingw32/include/stdio.h:231: undefined reference to `__mingw_vsscanf'
    CMakeFiles\opencv_world.dir/objects.a(persistence.cpp.obj): In function `strtod':
    D:/Qt/Qt5.8.0/Tools/mingw530_32/i686-w64-mingw32/include/stdlib.h:399: undefined reference to `__mingw_strtod'
    D:/Qt/Qt5.8.0/Tools/mingw530_32/i686-w64-mingw32/include/stdlib.h:399: undefined reference to `__mingw_strtod'
    CMakeFiles\opencv_world.dir/objects.a(data.cpp.obj): In function `strtod':
    D:/Qt/Qt5.8.0/Tools/mingw530_32/i686-w64-mingw32/include/stdlib.h:399: undefined reference to `__mingw_strtod'
    D:/Qt/Qt5.8.0/Tools/mingw530_32/i686-w64-mingw32/include/stdlib.h:399: undefined reference to `__mingw_strtod'
    D:/Qt/Qt5.8.0/Tools/mingw530_32/i686-w64-mingw32/include/stdlib.h:399: undefined reference to `__mingw_strtod'
    CMakeFiles\opencv_world.dir/objects.a(haar.cpp.obj): In function `sscanf':
    D:/Qt/Qt5.8.0/Tools/mingw530_32/i686-w64-mingw32/include/stdio.h:231: undefined reference to `__mingw_vsscanf'
    CMakeFiles\opencv_world.dir/objects.a(THDiskFile.cpp.obj): In function `fscanf':
    D:/Qt/Qt5.8.0/Tools/mingw530_32/i686-w64-mingw32/include/stdio.h:253: undefined reference to `__mingw_vfscanf'
    CMakeFiles\opencv_world.dir/objects.a(rgbe.cpp.obj): In function `sscanf':
    D:/Qt/Qt5.8.0/Tools/mingw530_32/i686-w64-mingw32/include/stdio.h:231: undefined reference to `__mingw_vsscanf'
    CMakeFiles\opencv_world.dir/objects.a(cap_images.cpp.obj): In function `sscanf':
    D:/Qt/Qt5.8.0/Tools/mingw530_32/i686-w64-mingw32/include/stdio.h:231: undefined reference to `__mingw_vsscanf'
    CMakeFiles\opencv_world.dir/objects.a(window_QT.cpp.obj): In function `ZN11GuiReceiverC2Ev':
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.cpp:798: undefined reference to `vtable for GuiReceiver'
    CMakeFiles\opencv_world.dir/objects.a(window_QT.cpp.obj): In function `ZN11GuiReceiverD2Ev':
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.cpp:827: undefined reference to `vtable for GuiReceiver'
    CMakeFiles\opencv_world.dir/objects.a(window_QT.cpp.obj): In function `ZN10CvTrackbar2trEPKcS1_i':
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.h:238: undefined reference to `CvTrackbar::staticMetaObject'
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.h:238: undefined reference to `CvTrackbar::staticMetaObject'
    CMakeFiles\opencv_world.dir/objects.a(window_QT.cpp.obj): In function `ZN12CvPushButtonC2EP11CvButtonbar7QStringPFviPvES3_':
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.cpp:1480: undefined reference to `vtable for CvPushButton'
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.cpp:1480: undefined reference to `vtable for CvPushButton'
    CMakeFiles\opencv_world.dir/objects.a(window_QT.cpp.obj): In function `ZN10CvCheckBoxC2EP11CvButtonbar7QStringPFviPvES3_i':
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.cpp:1502: undefined reference to `vtable for CvCheckBox'
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.cpp:1502: undefined reference to `vtable for CvCheckBox'
    CMakeFiles\opencv_world.dir/objects.a(window_QT.cpp.obj): In function `ZN13CvRadioButtonC2EP11CvButtonbar7QStringPFviPvES3_i':
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.cpp:1525: undefined reference to `vtable for CvRadioButton'
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.cpp:1525: undefined reference to `vtable for CvRadioButton'
    CMakeFiles\opencv_world.dir/objects.a(window_QT.cpp.obj): In function `ZN8CvWindowD2Ev':
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.cpp:1687: undefined reference to `vtable for CvWindow'
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.cpp:1687: undefined reference to `vtable for CvWindow'
    CMakeFiles\opencv_world.dir/objects.a(window_QT.cpp.obj): In function `ZN15DefaultViewPort2trEPKcS1_i':
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.h:479: undefined reference to `DefaultViewPort::staticMetaObject'
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.h:479: undefined reference to `DefaultViewPort::staticMetaObject'
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.h:479: undefined reference to `DefaultViewPort::staticMetaObject'
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.h:479: undefined reference to `DefaultViewPort::staticMetaObject'
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.h:479: undefined reference to `DefaultViewPort::staticMetaObject'
    CMakeFiles\opencv_world.dir/objects.a(window_QT.cpp.obj):D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.h:479: more undefined references to `DefaultViewPort::staticMetaObject' follow
    CMakeFiles\opencv_world.dir/objects.a(window_QT.cpp.obj): In function `ZN11CvButtonbarC2EP7QWidget7QString':
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.cpp:1424: undefined reference to `vtable for CvButtonbar'
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.cpp:1424: undefined reference to `vtable for CvButtonbar'
    CMakeFiles\opencv_world.dir/objects.a(window_QT.cpp.obj): In function `ZN11CvButtonbar2trEPKcS1_i':
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.h:171: undefined reference to `CvButtonbar::staticMetaObject'
    CMakeFiles\opencv_world.dir/objects.a(window_QT.cpp.obj): In function `ZN15CvWinPropertiesC2E7QStringP7QObject':
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.cpp:1552: undefined reference to `vtable for CvWinProperties'
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.cpp:1552: undefined reference to `vtable for CvWinProperties'
    CMakeFiles\opencv_world.dir/objects.a(window_QT.cpp.obj): In function `ZN15DefaultViewPort2trEPKcS1_i':
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.h:479: undefined reference to `DefaultViewPort::staticMetaObject'
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.h:479: undefined reference to `DefaultViewPort::staticMetaObject'
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.h:479: undefined reference to `DefaultViewPort::staticMetaObject'
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.h:479: undefined reference to `DefaultViewPort::staticMetaObject'
    CMakeFiles\opencv_world.dir/objects.a(window_QT.cpp.obj): In function `ZN8CvWindow2trEPKcS1_i':
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.h:288: undefined reference to `CvWindow::staticMetaObject'
    CMakeFiles\opencv_world.dir/objects.a(window_QT.cpp.obj): In function `ZN15DefaultViewPortC2EP8CvWindowi':
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.cpp:2410: undefined reference to `vtable for DefaultViewPort'
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.cpp:2410: undefined reference to `vtable for DefaultViewPort'
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.cpp:2410: undefined reference to `vtable for DefaultViewPort'
    CMakeFiles\opencv_world.dir/objects.a(window_QT.cpp.obj): In function `ZN8CvWindowC2E7QStringi':
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.cpp:1622: undefined reference to `vtable for CvWindow'
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.cpp:1622: undefined reference to `vtable for CvWindow'
    CMakeFiles\opencv_world.dir/objects.a(window_QT.cpp.obj): In function `ZN15DefaultViewPortD2Ev':
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.cpp:2444: undefined reference to `vtable for DefaultViewPort'
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.cpp:2444: undefined reference to `vtable for DefaultViewPort'
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.cpp:2444: undefined reference to `vtable for DefaultViewPort'
    CMakeFiles\opencv_world.dir/objects.a(window_QT.cpp.obj): In function `ZN10CvTrackbarC2EP8CvWindow7QStringPiiPFviPvES4_':
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.cpp:1295: undefined reference to `vtable for CvTrackbar'
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.cpp:1295: undefined reference to `vtable for CvTrackbar'
    CMakeFiles\opencv_world.dir/objects.a(window_QT.cpp.obj): In function `ZN10CvTrackbarC2EP8CvWindow7QStringPiiPFviE':
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.cpp:1305: undefined reference to `vtable for CvTrackbar'
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.cpp:1305: undefined reference to `vtable for CvTrackbar'
    CMakeFiles\opencv_world.dir/objects.a(window_QT.cpp.obj): In function `ZN15CvWinPropertiesD2Ev':
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.cpp:1610: undefined reference to `vtable for CvWinProperties'
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.cpp:1610: undefined reference to `vtable for CvWinProperties'
    CMakeFiles\opencv_world.dir/objects.a(window_QT.cpp.obj): In function `ZN15DefaultViewPort2trEPKcS1_i':
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.h:479: undefined reference to `DefaultViewPort::staticMetaObject'
    D:/opencv/opencv-3.3.0/opencv-3.3.0/modules/highgui/src/window_QT.h:479: undefined reference to `DefaultViewPort::staticMetaObject'
    ../../3rdparty/lib/liblibprotobuf.a(strtod.cc.obj): In function `strtod':
    D:/Qt/Qt5.8.0/Tools/mingw530_32/i686-w64-mingw32/include/stdlib.h:399: undefined reference to `__mingw_strtod'
    D:/Qt/Qt5.8.0/Tools/mingw530_32/i686-w64-mingw32/include/stdlib.h:399: undefined reference to `__mingw_strtod'
    ../../3rdparty/lib/libzlib.a(gzlib.c.obj): In function `snprintf':
    D:/Qt/Qt5.8.0/Tools/mingw530_32/i686-w64-mingw32/include/stdio.h:557: undefined reference to `__ms_vsnprintf'
    ../../3rdparty/lib/libzlib.a(gzwrite.c.obj): In function `vsnprintf':
    D:/Qt/Qt5.8.0/Tools/mingw530_32/i686-w64-mingw32/include/stdio.h:545: undefined reference to `__ms_vsnprintf'
    ../../3rdparty/lib/liblibpng.a(pngwrite.c.obj): In function `gmtime':
    D:/Qt/Qt5.8.0/Tools/mingw530_32/i686-w64-mingw32/include/time.h:219: undefined reference to `_gmtime32'
    ../../3rdparty/lib/liblibjasper.a(jas_stream.c.obj): In function `vsnprintf':
    D:/Qt/Qt5.8.0/Tools/mingw530_32/i686-w64-mingw32/include/stdio.h:545: undefined reference to `__ms_vsnprintf'
    collect2.exe: error: ld returned 1 exit status
    mingw32-make.exe[2]: *** [bin/libopencv_world330.dll] Error 1
    mingw32-make.exe[1]: *** [modules/world/CMakeFiles/opencv_world.dir/all] Error 2
    mingw32-make.exe: *** [all] Error 2
    modules\world\CMakeFiles\opencv_world.dir\build.make:9481: recipe for target 'bin/libopencv_world330.dll' failed
    CMakeFiles\Makefile2:1349: recipe for target 'modules/world/CMakeFiles/opencv_world.dir/all' failed
    Makefile:161: recipe for target 'all' failed
    23:16:37: 进程"C:\Program Files\CMake\bin\cmake.exe"退出,退出代码 2。
    Error while building/deploying project OpenCV (kit: Desktop Qt 5.8.0 MinGW 32bit)
    When executing step "Make"
    

    后面问题都先不管了,但是最前面的 undefined reference to '__mingw_vfscanf'以及 undefined reference to '__ms_vsnprintf'这类问题不知道什么原因。查了资料之后发现有类似的一个帖子说是编译工具链的问题,但是除了 cmake 其他的都是 QT 内置的啊。大佬请赐教。

    9 条回复    2018-12-04 19:28:32 +08:00
    EvanG
        1
    EvanG  
       2018-12-04 16:43:35 +08:00
    换个版本试试。有时就是很玄学。我的 cmake3.11.1 编 Opencv320 没出错。
    GhostRider
        2
    GhostRider  
    OP
       2018-12-04 16:58:10 +08:00
    @EvanG 老哥你的 Cmake 是 64 位的么,会不会是 camke 需要 32 位的啊==
    Justkkk
        3
    Justkkk  
       2018-12-04 17:00:53 +08:00
    opencv 直接就可以在 Qt 里面用啊,为什么要自己编译
    GhostRider
        4
    GhostRider  
    OP
       2018-12-04 17:18:11 +08:00
    @Justkkk 编译 OPenCV 的库啊,动态库 静态库啥,安装好的之后 win64 位的可以直接用 32 位的不行
    Justkkk
        5
    Justkkk  
       2018-12-04 17:20:15 +08:00
    @GhostRider 你就想编译一个 32 们的 opencv?
    EvanG
        6
    EvanG  
       2018-12-04 17:27:33 +08:00
    Justkkk
        7
    Justkkk  
       2018-12-04 17:28:12 +08:00
    WITH_QT 这个选项 只是使 opencv 的 gui 用 qt 的 ui,如果只是用 opencv 处理图像,这个是基本不需要的。老版本(如 2.49 )的 opencv 发布的版本里面 是同时有 32bit 和 64bit 的,如果不想折腾,下一个老版本的就行了
    GhostRider
        8
    GhostRider  
    OP
       2018-12-04 17:43:32 +08:00
    @EvanG 多谢 老哥
    GhostRider
        9
    GhostRider  
    OP
       2018-12-04 19:28:32 +08:00
    @Justkkk 可以的老哥 再折腾一下
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2813 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 03:32 · PVG 11:32 · LAX 19:32 · JFK 22:32
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.