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

2018-12-11 16:51:31 +08:00
 GhostRider

我在 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 文件里面了,但是就是抱着个错,不知为啥。

6593 次点击
所在节点    Qt
5 条回复
sbw
2018-12-11 16:57:24 +08:00
链接 dll 的 export lib 了没?
GhostRider
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
2018-12-11 17:36:46 +08:00
libs += 应该是 *.lib 文件
dll 动态链接库是在运行时需要的
GhostRider
2018-12-11 17:49:34 +08:00
@pagict 我的是使用 minGW 编译的 对应 *.lib 的文件是 *.dll.a。*dll 和 *.dll.a 任何一个都行。但是出现的错误时一样的。
wbing
2018-12-11 17:58:49 +08:00
你引用动态库方式不对吧,记得是要后面带上-l 的

LIBS += -LD:\opencv\build\mingw\x86\mingw\bin\ -lopencv_highgui330 -lopencv_calib3d330 。。。。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/516572

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX