Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

build openCV & Qt project and link error:undefined reference and bad reloc address 0x1 in section

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...