我在 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
sbw 2018-12-11 16:57:24 +08:00
链接 dll 的 export lib 了没?
|
2
GhostRider OP @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 ``` |
3
pagict 2018-12-11 17:36:46 +08:00
libs += 应该是 *.lib 文件
dll 动态链接库是在运行时需要的 |
4
GhostRider OP @pagict 我的是使用 minGW 编译的 对应 *.lib 的文件是 *.dll.a。*dll 和 *.dll.a 任何一个都行。但是出现的错误时一样的。
|
5
wbing 2018-12-11 17:58:49 +08:00
你引用动态库方式不对吧,记得是要后面带上-l 的
LIBS += -LD:\opencv\build\mingw\x86\mingw\bin\ -lopencv_highgui330 -lopencv_calib3d330 。。。。 |