Ask Your Question

How to Link OpenCV 2.4.9 & Qt in MacOS

asked 2014-09-11 04:12:37 -0500

Macs gravatar image

Hello there...

I have installed OpenCV using Homebrew in Mac OS Mavericks and QT Creator from the website.

I am trying to test OpenCV & QT Creator using a simple program from the internet, but I am ending up with some errors.

I donno wats going wrong.... I am new to Opencv and QT ... Your Help is much appreciated..

Below are my project details. Guide me for my first ever OpenCV & QT with Mac OS X Program......


--- File ---

QT += core

QT -= gui

TARGET = untitled1

CONFIG += console

CONFIG -= app_bundle


SOURCES += main.cpp

LIBS += -L/usr/local/Cellar/opencv/2.4.9/lib \

       -lopencv_highgui \

       -lopencv_imgproc \

       -lopencv_core \

       -lopencv_features2d \

       -lopencv_calib3d \

INCLUDEPATH += /usr/local/Cellar/opencv/2.4.9/include \

--- Source File - main.cpp ---

include opencv2/core/core.hpp

include opencv2/highgui/highgui.hpp

include iostream

include opencv/cv.h

using namespace cv;

int main()


    std::cout << "Hello World!" << std::endl;

    cv::Mat mat;

    mat = cv::imread("Unknown.JPEG");




    return 0;

--- The Compile Output with Errors ---

14:30:57: Running steps for project untitled... 14:30:57: Configuration unchanged, skipping qmake step. 14:30:57: Starting: "/usr/bin/make" /Users/Macs/Qt/5.3.1/bin/qmake -spec macx-g++ CONFIG+=debug CONFIG+=x86_64 -o Makefile ../untitled/ /Applications/ -headerpad_max_install_names -Wl,-syslibroot,/Applications/ -mmacosx-version-min=10.6 -o untitled main.o -F/usr/local/Cellar/qt5/5.3.1/lib -L/usr/local/Cellar/opencv/2.4.9/lib -lopencv_highgui -lopencv_imgproc -lopencv_core -lopencv_features2d -lopencv_calib3d -framework QtCore Undefined symbols for architecture x86_64: "cv::imread(std::string const&, int)", referenced from: _main in main.o "cv::imshow(std::string const&, cv::_InputArray const&)", 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: * [untitled] Error 1 14:30:57: The process "/usr/bin/make" exited with code 2. Error while building/deploying project untitled (kit: Desktop) When executing step "Make" 14:30:57: Elapsed time: 00:00.

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted

answered 2014-09-14 06:09:24 -0500

Macs gravatar image

Hi !

Gud News .... works like charm

I restored my Mac with Time Machine and I just build OpenCV 2.4.9 from the source, added Kits & Version to QT creator its working now....

I am using Mac OS X 10.9.4, OpenCV 2.4.9, and Qt Creator 3.2.0 Based on Qt 5.3.1 (Clang 5.0 (Apple), 64 bit)

Thanks for your support.... Macs

edit flag offensive delete link more


Glad it worked out for you. Have fun :)

KellyWilson gravatar imageKellyWilson ( 2014-09-15 00:04:41 -0500 )edit

answered 2014-09-11 16:32:52 -0500

Hello Macs,

When you run into this problem of 'undefined symbols' with MacOS and opencv, I think it is because the calling conventions are different for clang++ C99 and c++11 (it shows you are calling g++ but on Mavericks that is symlinked to clang IIRC...unless you are actually using g++ installed with brew or some such...but then this error probably wouldn't happen). What you need to do is add:

QMAKE_CXXFLAGS+=-std=c++11 QMAKE_CXXFLAGS+=-stdlib=libc++

QMAKE_LFLAGS+=-std=c++11 QMAKE_LFLAGS+=-stdlib=libc++

to your .pro file. You will also need to add:


because libc++ is only supported on 10.7+. And that should fix things... YMMV ;)

Thanks, K.Wilson

P.S. Please post back if this fixes things, as it may help others.

edit flag offensive delete link more


Thanks for your reply....will check this and revert back to you....

Macs gravatar imageMacs ( 2014-09-14 02:47:50 -0500 )edit

I got the below error on including those two line to .pro.

clang: error: no such file or directory: 'QMAKE_CXXFLAGS+=-stdlib=libc++' make: * [main.o] Error 1 13:51:31: The process "/usr/bin/make" exited with code 2. Error while building/deploying project OpencvTest (kit: Desktop) When executing step "Make"

Macs gravatar imageMacs ( 2014-09-14 03:23:09 -0500 )edit
Login/Signup to Answer

Question Tools


Asked: 2014-09-11 04:12:37 -0500

Seen: 3,522 times

Last updated: Sep 14 '14