main.cpp:-1: error: undefined reference to `cvLoadImage'

时间:2016-07-11 21:07:11

标签: c++ opencv qt-creator

I want to compile easy programm in qt creator, but I have problems with opencv. Os- ubuntu 16.04 .pro file qt

LIBS += -lopencv_core -lopencv_imgproc -lopencv_highgui

Main program

#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <stdlib.h>
#include <stdio.h>

IplImage* image = 0;
IplImage* src = 0;

int main()
{
    char* filename = "Image0.jpg";
    image = cvLoadImage(filename,1);
    src = cvCloneImage(image);
    return 0;
}

Compilation error main.cpp:-1: error: undefined reference to `cvLoadImage'. What I am doing wrong?

1 个答案:

答案 0 :(得分:1)

It seems you're not linking against the OpenCV libraries correctly (or for some reason the linking is not working), the code itself is compiling.

Take a look at the answers to a similar question, that will most probably help you.

And by the way, cvLoadImage and IplImage are from the old C-API, avoid those. Use cv::Mat img=cv::imread("img.png"), instead.