Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Using QT with openCV on Maverick osX



  • Hello

    I am new to openCV and I would like to install openCV and use it with QT.
    I used macports to install it and i set the path in the terminal.

    What I did was;

    I installed macports
    I typed in the terminal
    @
    export PATH=$PATH:/opt/local/bin
    source .profile
    sudo port -v selfupdate
    sudo port install opencv
    @
    restart
    Thats all...

    Now i try to compile a Helloworld but i get unknown variable error. Looks like something with the linker gone wrong or i included the wrong libs? I searched google and I found some hints but nothing helped yet. Maybe someone got a suggestion?
    Thank you very much for your time and answer!

    My settings:
    @
    #-------------------------------------------------
    #
    # Project created by QtCreator 2014-02-04T22:10:07
    #
    #-------------------------------------------------

    QT       += core
    
    QT       -= gui
    
    TARGET = opencvTest
    CONFIG   += console
    CONFIG   -= app_bundle
    
    TEMPLATE = app
    
    SOURCES += main.cpp
    
    INCLUDEPATH += /opt/local/include
    
    LIBS += -L/opt/local/lib
    LIBS += -lopencv_core
            -lopencv_highgui
    

    @

    @
    #include <iostream>
    #include <opencv2/highgui/highgui.hpp>

    using namespace std ;
    using namespace cv ;
    
    int main()
    {
        Mat img ;
    
        img = imread("unknown.jpg") ;
    
        return 0;
    }
    

    @
    Error message

    @
    10:39:10: Running steps for project opencvTest...
    10:39:10: Configuration unchanged, skipping qmake step.
    10:39:10: Starting: "/usr/bin/make"
    /Users/Ben/Qt/5.2.0/clang_64/bin/qmake -spec macx-g++ CONFIG+=debug CONFIG+=x86 CONFIG+=declarative_debug CONFIG+=qml_debug -o Makefile ../opencvTest/opencvTest.pro
    /Applications/Xcode.app/Contents/Developer/usr/bin/g++ -headerpad_max_install_names -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -mmacosx-version-min=10.6 -o opencvTest main.o -F/Users/Ben/Qt/5.2.0/clang_64/lib -L/opt/local/lib -lopencv_core -framework QtCore
    Undefined symbols for architecture x86_64:
    "cv::imread(std::string 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: *** [opencvTest] Error 1
    10:39:10: The process "/usr/bin/make" exited with code 2.
    Error while building/deploying project opencvTest (kit: Unnamed)
    When executing step 'Make'
    10:39:10: Elapsed time: 00:00.@


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Check your opencv install to see if it was build for x86_64



  • Hmm it should be, Macport installs it as a 64bit as default as I know from google.
    I don't know how I can check that honestly.


  • Lifetime Qt Champion

    call

    @file /opt/local/lib/libopencv_core.dylib@

    in your console



  • so....
    /opt/local/lib/libopencv_core.dylib: Mach-O 64-bit dynamically linked shared library x86_64

    thats the result so I think its the right one? isn't it?



  • Yeaah it works! Finally!

    /Users/Ben/Qt/5.2.0/clang_64/mkspecs/macx-clang/qmake.conf
    

    had to change

    QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.6
    

    to

    QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.9
    


  • BUT... other libs like boost won't work anymore...

    I have to add
    QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.9
    to the pro file in the project for the opencv projects separately


  • Lifetime Qt Champion

    You'll have to check that all your libraries have the same deployment target. That might also mean rebuild Qt


Log in to reply