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

QT5.8 + opencv 3.30 例子报错 undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'

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

    我在 WIN10 上的 QT5.8 编译了 opencv3.30 的动态库。写了个例子,如下:

    #include <iostream>
    
    #include "opencv2/opencv.hpp"
    using namespace std;
    
    int main()
    {
        cv::Mat image = cv::imread("1.jpg",1);
        if(image.data == 0){
            cout << "No Image" <<endl;
            //exit(1);
        }
        else{
            cout << "Image" << endl;
        }
        cv::namedWindow("My Image");
        cv::imshow("My Image", image);
        system("pause");
        return 0;
    }
    
    

    编译的时候显示错误:

    release/main.o:main.cpp:(.text.startup+0x170): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
    collect2.exe: error: ld returned 1 exit status
    

    动态链接库我也进全部加在 test.pro 文件里面了,但是就是抱着个错,不知为啥。

    第 1 条附言  ·  2018-12-12 17:27:40 +08:00
    原因找到了,我编译的 opencv 是 release 版本的 编译一个 debug 版本的就好了。
    5 条回复    2018-12-11 17:58:49 +08:00
    sbw
        1
    sbw  
       2018-12-11 16:57:24 +08:00
    链接 dll 的 export lib 了没?
    GhostRider
        2
    GhostRider  
    OP
       2018-12-11 17:09:35 +08:00
    @sbw 啥意思? dll 的文件夹已经增加到环境变量了。qt 的 pro 文件如下:
    ```C++
    INCLUDEPATH += D:\opencv\build\mingw\include

    LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_highgui330.dll
    LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_calib3d330.dll
    LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_dnn330.dll
    LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_features2d330.dll
    LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_flann330.dll
    LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_imgcodecs330.dll
    LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_imgproc330.dll
    LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_ml330.dll
    LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_objdetect330.dll
    LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_photo330.dll
    LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_shape330.dll
    LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_stitching330.dll
    LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_superres330.dll
    LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_video330.dll
    LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_videoio330.dll
    LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_videostab330.dll
    LIBS += D:\opencv\build\mingw\x86\mingw\bin\opencv_ffmpeg330.dll
    LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_core330.dll
    ```
    pagict
        3
    pagict  
       2018-12-11 17:36:46 +08:00
    libs += 应该是 *.lib 文件
    dll 动态链接库是在运行时需要的
    GhostRider
        4
    GhostRider  
    OP
       2018-12-11 17:49:34 +08:00
    @pagict 我的是使用 minGW 编译的 对应 *.lib 的文件是 *.dll.a。*dll 和 *.dll.a 任何一个都行。但是出现的错误时一样的。
    wbing
        5
    wbing  
       2018-12-11 17:58:49 +08:00
    你引用动态库方式不对吧,记得是要后面带上-l 的

    LIBS += -LD:\opencv\build\mingw\x86\mingw\bin\ -lopencv_highgui330 -lopencv_calib3d330 。。。。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2777 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 21ms · UTC 13:26 · PVG 21:26 · LAX 05:26 · JFK 08:26
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.