I have built the release version of openCV 4.5.1 shared library with CMake 3.91.2 & MinGW-W64 GCC-6.4.0 i686-posix-dwarf with default compile config.
Tried to use the libraries with Qt 5.4 & MinGW 4.9.1 32 bit.
I'm in Windows 10 64 bit.
Here's my .pro
:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = test05
TEMPLATE = app
CONFIG += c++11
SOURCES += main.cpp
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
INCLUDEPATH += $$PWD/include
LIBS += -L$$PWD/lib/opencv -lopencv_highgui451.dll -lopencv_core451.dll -lopencv_imgcodecs451.dll -lopencv_imgproc451.dll
Here's main.cpp
#include "mainwindow.h"
#include <QApplication>
#include "opencv2/opencv.hpp"
using namespace std;
using namespace cv;
int main(int argc, char** argv) {
Mat image = imread("D:\test.jpg");
namedWindow("window", WINDOW_AUTOSIZE );
imshow("window",image);
waitKey(0);
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
Here's build output:
E:workspaceest05main.cpp:-1: error: undefined reference to `cv::imread(std::string const&, int)'
E:workspaceest05main.cpp:-1: error: undefined reference to `cv::namedWindow(std::string const&, int)'
E:workspaceest05main.cpp:-1: error: undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'
:-1: error: release/main.o: bad reloc address 0x1 in section `.text$_ZN7cvflann7anyimpl21typed_base_any_policyIbE4typeEv[__ZN7cvflann7anyimpl21typed_base_any_policyIbE4typeEv]'
collect2.exe:-1: error: error: ld returned 1 exit status
I have googled a lot,these two questions seems close to my situation but could not solve my problem:
EDIT:
Thank for your advice,I deleted the GUI part and tried these:
LIBS += E:workspaceest05libopencvlibopencv_core451.dll.a
LIBS += E:workspaceest05libopencvlibopencv_core451.dll
Both don't work,the issues keep the same as above.I don't know if I built the shared library correctly or it's a simple link error?
question from:
https://stackoverflow.com/questions/65558045/build-opencv-qt-project-and-link-errorundefined-reference-and-bad-reloc-addre 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…