Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

c++ - Adding opencv library to QT creator and getting error: linker command failed with exit code 1

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?

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...