Error first OPENCV project on Raspberry Pi 2

  • Hello.

    I'm trying to run Opencv on raspberry and i can't... In Windows, I work with Qt and OpenCv without problems, but in Raspberry appears an error with all funtions:

    My code is:

       QT       += core gui
       greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
       TARGET = temporal
       TEMPLATE = app
        SOURCES += main.cpp\
        HEADERS  += mainwindow.h
        FORMS    += mainwindow.ui
        INCLUDEPATH +=/usr/local/include
        LIBS += -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -lopencv_highgui


        #ifndef MAINWINDOW_H
        #define MAINWINDOW_H
        #include <opencv2/core/core.hpp>
        #include <opencv2/highgui/highgui.hpp>
        #include <opencv2/imgproc/imgproc.hpp>
        #include <QMainWindow>
        #include <iostream>
        #include <stdio.h>
        #include <stdlib.h>
        namespace Ui {
        class MainWindow;
        class MainWindow : public QMainWindow
            explicit MainWindow(QWidget *parent = 0);
        private slots:
            void on_pushButton_clicked();
            Ui::MainWindow *ui;
        #endif // MAINWINDOW_H


        #include "mainwindow.h"
        #include <QApplication>
        int main(int argc, char *argv[])
            QApplication a(argc, argv);
            MainWindow w;


        #include "mainwindow.h"
        #include "ui_mainwindow.h"
        #include <opencv2/highgui/highgui.hpp>
        using namespace cv;
        MainWindow::MainWindow(QWidget *parent) :
            ui(new Ui::MainWindow)
            delete ui;
        void MainWindow::on_pushButton_clicked()
            Mat img = imread("/home/pi/test.png",1);

    I make test and the problem appears when i write the function, in this case, imread. And the error is:

    mainwindow.o: undefined reference to symbol '_ZN2cv6String10deallocateEv'
    error adding symbols: DSO missing from command line
    collect2: error: Id returned 1 exit status

    Any idea??

    Many thanks!!!

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Are you building directly on the Pi2 ?

  • @SGaist Yes, I make this project on Qt in Raspberry. I installed opencv following this video:

  • Lifetime Qt Champion

    Looks like for some reason there's a symbol from opencv_core that is not found. Can you try to build a basic main.cpp only using OpenCV ?

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.