Ask Your Question

kenjif's profile - activity

2016-10-31 05:42:35 -0600 asked a question Trouble linking openCV 2.4.13.1 on QT creator 4.1.0 on OS X El Capitan

Hello opencv users !

I have to use openCV 2.4.13.1 and QT Creator for a school project. I have been struggling to link openCV in my QT application.

I installed openCV using homebrew, the command pkg-config --modversion opencv returns 2.4.13.1.

I installed QT Creator from the official site, running the 4.1.0 version. And I am working on a machine running on OS X El Capitan version 10.11.6.

Here is my .pro code :

QT += core
QT -= gui

QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.9
QMAKE_CXXFLAGS += -std=c++11
QMAKE_CXXFLAGS += -stdlib=libc++
QMAKE_LFLAGS += -std=c++11
QMAKE_LFLAGS += -stdlib=libc++

CONFIG += c++11
PKGCONFIG =+ opencv

TARGET = OpenCV_HelloWorld
CONFIG += console
CONFIG -= app_bundle

TEMPLATE = app
SOURCES += main.cpp

INCLUDEPATH += /usr/local/Cellar/opencv/2.4.13.1/include \
LIBS += -L/usr/local/Cellar/opencv/2.4.13.1/lib \
LIBS += -libopencv_core.2.4.13 \
    -libopencv_imgproc.2.4.13 \
    -libopencv_highgui.2.4.13

And here my main.cpp file :

#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv/cv.h"

int main(int argc, char** argv){

    cv::namedWindow("Image");
    return 1;

}

When running qmake and building in QT Creator, I get a linker command error and a symbol not found error.

Undefined symbols for architecture x86_64:
  "cv::namedWindow(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)", referenced from:
      _main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [OpenCV_HelloWorld] Error 1
17:48:42: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project OpenCV_HelloWorld (kit: Desktop Qt 5.7.0 clang 64bit)
When executing step "Make"

I tried a lot of different things unfortunately to no success. If anyone has a suggestion on how to fix this, it will be very much appreciated. I apologize for mistakes, english not being my main language.

Thank you very much for your time.