Adding opencv library to QT creator and getting er

2019-02-20 10:25发布

i'm new to qt and i installed the qt creator on my mac (os 10.8.5) and wanted to add the openCv library. I followed the instruction of this youtube tutorial (http://www.youtube.com/watch?v=i9hYiMXLZRs).. don't know if that matters.

my untitled5.pro file:

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = untitled5
TEMPLATE = app

INCLUDEPATH = /usr/local/include

SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h

LIBS += -L/usr/local/lib \
     -1ibopencv_core \
     -1ibopencv_imgproc \
     -1ibopencv_features2d \
     -1ibopencv_highgui

FORMS    += mainwindow.ui

and the main.cpp:

#include "mainwindow.h"
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    IplImage* img = 0;
    img = cvLoadImage("/Users/path/to/image.jpg");
    cvNamedWindow("Example1", CV_WINDOW_AUTOSIZE);
    cvShowImage("Example1", img);
    cvWaitKey(0);
    cvReleaseImage(&img);
    cvDestroyWindow("Example1");

    return a.exec();
}

It's just some code to test the library opencv. By running this code, i get two errors:

linker command failed with exit code 1 (use -v to see invocation)
[untitled5.app/Contents/MacOS/untitled5] Error 1

I absolute don't have a clue what to do, searching for answers for hours. Maybe someone can help me. Can you tell me what does the error message say and what could i've done wrong?

1条回答
看我几分像从前
2楼-- · 2019-02-20 10:36

Check your library names. In your pro file the first letter is 1 (number) instead of l:

-libopencv_core \
-libopencv_imgproc \
-libopencv_features2d \
-libopencv_highgui
查看更多
登录 后发表回答