I tried to set up opencv in qt and followed the steps exactly from here https://wiki.qt.io/How_to_setup_Qt_and_openCV_on_Windows, but got linking error like
"undefined reference to
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: undefined reference to `cv::imread(cv::String const&, >int)'"
Here's the path of my opencv: C:\opencv-build\install\x86\mingw\lib
Things I tried: Using the "add library" on Qt. However, qt coudlnt find the file that I specified.
My code: .pro file
#-------------------------------------------------
#
# 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
main
#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;
}
I appreciate any kind of help. Thanks!
CodePudding user response:
Try specifying LIBS as LIBS = -Lpath/to/lib -llibname
qmake reference
LIBS = -LC:\opencv-build\bin -lopencv_core343 -lopencv_highgui343 -lopencv_imgcodecs343 -lopencv_imgproc343 -lopencv_features2d343 -lopencv_calib3d343