[英]qt and Opencv linking error "undefined reference"
我尝试在 qt 中设置 opencv 并完全按照此处https://wiki.qt.io/How_to_setup_Qt_and_openCV_on_Windows的步骤操作,但出现链接错误,例如
“未定义对
cv::imread(cv::String const&, int)' debug/mainwindow.o: In function
MainWindow::MainWindow(QWidget*)' 中:C:\Users\Han\Desktop\QT_projects\build-TEST_OPENCV -Desktop_Qt_5_15_2_MinGW_64_bit->Debug/../TEST_OPENCV/mainwindow.cpp:17: 未定义引用 `cv::imread(cv::String const&, >int)'"
这是我的opencv的路径: C:\opencv-build\install\x86\mingw\lib
我尝试过的事情:在 Qt 上使用“添加库”。 但是,qt 无法找到我指定的文件。
我的代码:.pro 文件
#-------------------------------------------------
#
# Project created by QtCreator 2017-03-05T12:30:06
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = opencvtest
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
INCLUDEPATH += C:\opencv\build\include
LIBS += C:\opencv-build\bin\libopencv_core343.dll
LIBS += C:\opencv-build\bin\libopencv_highgui343.dll
LIBS += C:\opencv-build\bin\libopencv_imgcodecs343.dll
LIBS += C:\opencv-build\bin\libopencv_imgproc343.dll
LIBS += C:\opencv-build\bin\libopencv_features2d343.dll
LIBS += C:\opencv-build\bin\libopencv_calib3d343.dll
# more correct variant, how set includepath and libs for mingw
# add system variable: OPENCV_SDK_DIR=D:/opencv/opencv-build/install
# read http://doc.qt.io/qt-5/qmake-variable-reference.html#libs
#INCLUDEPATH += $$(OPENCV_SDK_DIR)/include
#LIBS += -L$$(OPENCV_SDK_DIR)/x86/mingw/lib \
# -lopencv_core320 \
# -lopencv_highgui320 \
# -lopencv_imgcodecs320 \
# -lopencv_imgproc320 \
# -lopencv_features2d320 \
# -lopencv_calib3d320
主要的
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// read an image
cv::Mat image = cv::imread("f://1.jpg", 1);
// create image window named "My Image"
cv::namedWindow("My Image");
// show the image on window
cv::imshow("My Image", image);
}
MainWindow::~MainWindow()
{
delete ui;
}
我感谢任何形式的帮助。 谢谢!
尝试将 LIBS 指定为LIBS += -Lpath/to/lib -llibname
qmake 参考
LIBS += -LC:\opencv-build\bin -lopencv_core343 -lopencv_highgui343 -lopencv_imgcodecs343 -lopencv_imgproc343 -lopencv_features2d343 -lopencv_calib3d343
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.