0

I am using a very basic OpenCV code to compile using Qt but every time the following errors are coming.

OpenCV version

    OpenCV version : 3.4.3
    Major version : 3
    Minor version : 4
    Subminor version : 3

My code

    #include <opencv2/core/core.hpp>
    #include <opencv2/highgui/highgui.hpp>
    #include <iostream>
    #include "opencv2/imgproc/imgproc_c.h"
    #include "opencv2/imgproc/imgproc.hpp"

    using namespace std;
    using namespace cv;

    int main()

    {
   Mat I = imread("path/filename.ppm", 1);

   imshow("conv_image",I);

   waitKey();

   return 0;

     }

.pro file

    QT -= gui

    CONFIG += c++11 console
    CONFIG -= app_bundle

    # The following define makes your compiler emit warnings if you 
    use
    # any feature of Qt which as been marked 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

    INCLUDEPATH += /usr/local/include/opencv
    LIBS += -L/usr/local/lib -lopencv_core -lopencv_imgcodecs - 
    lopencv_highgui

Given Error

:-1: warning: libopencv_core.so.3.4, needed by /usr/local/lib/libopencv_imgcodecs.so, may conflict with libopencv_core.so.2.4

:-1: error: main.o: undefined reference to symbol '_ZN2cv6String10deallocateEv'

/usr/local/lib/libopencv_core.so.3.4:-1: error: error adding symbols: DSO missing from command line

:-1: error: collect2: error: ld returned 1 exit status

In my .pro file, I have used the following line(from the different link I have found 3 ways, I have tried all but failed)

First

    INCLUDEPATH += /usr/local/include/opencv

    LIBS += -L/usr/local/lib -lopencv_core -lopencv_imgcodecs - 
    lopencv_highgui

Second

    INCLUDEPATH +=/usr/local/include/opencv

    LIBS +=`pkg-config --libs opencv`

Third

I have used information from here

Please give me suggestion to solve the issue.

user10634362
  • 549
  • 5
  • 21
  • With OpenCV v3, you only need include one file `opencv2/opencv.hpp` – Mark Setchell Jan 12 '19 at 13:50
  • I am not familiar with `.pro` files, but the `#` at the start of your lines looks like a comment to me. Can you show your actual file? – Mark Setchell Jan 12 '19 at 14:32
  • @MarkSetchell I have edited the ques and added the .pro file – user10634362 Jan 12 '19 at 16:23
  • Normally, when you build OpenCV you get a binary called `opencv_version` so can you find that and run `opencv_version -v` and add the output? – Mark Setchell Jan 12 '19 at 16:32
  • Here in the question I have added also the opencv version that I am using. – user10634362 Jan 12 '19 at 17:10
  • The command I suggested gives all the details about your installation to help you solve the problem, not just the version. – Mark Setchell Jan 12 '19 at 17:16
  • I have done it. **opencv_version** gives me 3.4.1 and the output of the second command I have uploaded [here](https://drive.google.com/open?id=1NKdvjxHOS5uVjeqkHIafqBQg5imN6Vay) as it is very long. – user10634362 Jan 12 '19 at 17:39
  • So your libraries appear to be in `/home/atif/anaconda3/lib` not in `/usr/local/lib` Please look in there and check. If they are there, you'll need to change to `LIBS += -L/usr/local/lib -L/home/atif/anaconda3/lib ...` – Mark Setchell Jan 12 '19 at 17:45
  • But this is for Python. I have installed OpenCV for C++ and Python and right now I am using a cpp code for OpenCV – user10634362 Jan 12 '19 at 17:53
  • The information you just added doesn't match your question. Your question has v3.4.3 and the information you just added is v3.4.1 – Mark Setchell Jan 12 '19 at 18:18
  • I have got the version 3.4.3 as a output using a cpp code of opencv. But in the terminal while I have written opencv_version it gave me 3.4.1. I think last one for opencv python because the link I have added in my last reply it was showing **lib in anaconda** and which is python actually. – user10634362 Jan 12 '19 at 18:32

0 Answers0