我尝试了两种方法来使用 opencv 和 qt creator 第一个使用 Mingw,其中 dll 和 .dll.a 文件已经与 opencv 库一起下载,我只是在 .pro 文件中添加对 .dll.a 文件的引用,如下所示
INCLUDEPATH += D:\\OpenCV\\opencv\\build\\include
LIBS += D:\\OpenCV\\opencv\\build\\x64\\mingw\\lib\\libopencv_calib3d242.dll.a
LIBS += D:\\OpenCV\\opencv\\build\\x64\\mingw\\lib\\libopencv_contrib242.dll.a
LIBS += D:\\OpenCV\\opencv\\build\\x64\\mingw\\lib\\libopencv_core242.dll.a
LIBS += D:\\OpenCV\\opencv\\build\\x64\\mingw\\lib\\libopencv_features2d242.dll.a
我有一个简单的代码来测试opencv:
#include <QtCore/QCoreApplication>
#include <opencv/cv.h>
using namespace cv;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Mat image;
return a.exec();
}
但我遇到了如下构建问题
C:\Users\Kato\Documents\QT projects\QtOpenCVYaRab\debug\main.o:-1: 在函数
~Mat': d:\OpenCV\opencv\build\include\opencv2\core\mat.hpp:278: error: undefined reference to
cv::fastFree(void*)' d:\OpenCV\opencv\build\include\opencv2\core\mat .hpp:367:错误:未定义对 `cv::Mat::deallocate()' 的引用:-1:错误:collect2:ld 返回 1 个退出状态
这是一些编译输出:
Running build steps for project QtOpenCVYaRab...
Configuration unchanged, skipping qmake step.
Starting: "C:\QtSDK\mingw\bin\mingw32-make.exe"
C:/QtSDK/mingw/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `C:/Users/Kato/Documents/QT projects/QtOpenCVYaRab'
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL
d:/OpenCV/opencv/build/include/opencv2/core/mat.hpp:278: undefined reference to `cv::fastFree(void*)'
debug/main.o:d:/OpenCV/opencv/build/include/opencv2/core/mat.hpp:367: undefined reference to `cv::Mat::deallocate()'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\QtOpenCVYaRab.exe] Error 1
mingw32-make: *** [debug] Error 2
The process "C:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
Error while building project QtOpenCVYaRab (target: Desktop)
When executing build step 'Make'
第二种方法是使用 cmake 编译 opencv 库,使用 Visual Studio 2010 构建它并添加对 bin 文件夹中文件的引用,但我遇到了几乎相同的构建问题。