Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Help with setting up OpenCV in QT on OSX

[SOLVED] Help with setting up OpenCV in QT on OSX

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 7.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    I'm new to QT and am having trouble setting up OpenCV for use with QT under OSX. Most of the information I've found on this pertains to Windows or Linux so I'm struggling. I've written an extensive post about "what I have tried so far over at stackOverflow":http://stackoverflow.com/questions/17518408/setting-up-opencv-in-qt-on-osx Rather than repost all that here, the gist is that I don't seem to be linking to the OpenCV libs correctly. The console output is below.

    I've tried various ways of specifying the lib path & libs in the project profile. OpenCV is correctly installed for OSX - the headers are at /usr/local/include and the libs at /usr/local/libs. Does QT require something different?

    If more detail or specifics are needed, please let me know or check out my post at "stackOverflow":http://stackoverflow.com/questions/17518408/setting-up-opencv-in-qt-on-osx

    • Thanks!

    - one attempt at defining the lib paths. Tried it without periods, etc.
    @
    LIBS += -L/usr/local/lib
    -1ibopencv_core.2.4.6
    -1ibopencv_imgproc.2.4.6
    -1ibopencv_features2d.2.4.6
    -1ibopencv_highgui.2.4.6@

    -Console output with error msg
    @02:44:38: Running steps for project RP_openCV_01...
    02:44:38: Configuration unchanged, skipping qmake step.
    02:44:38: Starting: "/usr/bin/make"
    clang++ -headerpad_max_install_names -mmacosx-version-min=10.6 -o RP_openCV_01 main.o -L/usr/local/lib -1ibopencv_core.2.4.6,dylib -1ibopencv_imgproc.2.4.6.dylib -F/Users/rise/Qt5.0.2/5.0.2/clang_64/lib -framework QtCore
    clang: warning: argument unused during compilation: '-1ibopencv_core.2.4.6,dylib'
    clang: warning: argument unused during compilation: '-1ibopencv_imgproc.2.4.6.dylib'
    Undefined symbols for architecture x86_64:
    "cv::_InputArray::_InputArray(cv::Mat const&)", referenced from:
    _main in main.o
    "cv::namedWindow(std::string const&, int)", referenced from:
    _main in main.o
    "cv::Mat::deallocate()", referenced from:
    _main in main.o
    "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
    "cv::waitKey(int)", referenced from:
    _main in main.o
    "cv::fastFree(void*)", 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: *** [RP_openCV_01] Error 1
    02:44:38: The process "/usr/bin/make" exited with code 2.
    Error while building/deploying project RP_openCV_01 (kit: Desktop Qt 5.0.2 clang 64bit)
    When executing step 'Make'@

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      That's wrong
      @
      -1ibopencv_core.2.4.6
      -1ibopencv_imgproc.2.4.6
      -1ibopencv_features2d.2.4.6
      -1ibopencv_highgui.2.4.6@

      It should rather be
      @

      -lopencv_core.2.4.6
      @

      Beware, not 1 but l

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        Thanks. I've tried it a bunch of different ways. I think what I posted above was the most recent desperate error-ridden attempt.

        I just tried with code below and get the same not found error (:-1: error: library not found for -libopencv_core.2.4.6). Also tried not including the version number, etc. and got the same error.

        Seems like I have some basic thing wrong and/or not set correctly. An environment var or ther setting.

        @INCLUDEPATH += /usr/local/include\

        LIBS += -L/usr/local/lib
        -libopencv_core.2.4.6
        -libopencv_imgproc.2.4.6
        -libopencv_features2d.2.4.6
        -libopencv_highgui.2.4.6@

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Because it's not -libopencv_core.2.4.6, it's -lopencv_core.2.4.6.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            Arrgh! Dumb errors. Thanks for pointing that out.

            There was some logic (albeit flawed) which got me to that point. On OSX the file name is libopencv_core.2.4.6.dylib and I was confused about the -l flag in the examples I was looking at.

            Here's a follow-up question: on my machine it looks like libopencv_core.dylib is an alias to libopencv_core.2.4.6.dylib . Am I correct in thinking that I should use the base lib name rather than the lib name which includes version numbers as I've seen in example code?

            In other words, using just the base name will accommodate future versions of a lib:

            @LIBS += -L/usr/local/lib
            -lopencv_core
            -lopencv_imgproc
            -lopencv_features2d
            -lopencv_highgui@

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              You're welcome, classic error :)

              That's the right way to do it yes

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • J Offline
                J Offline
                jorgeimp
                wrote on last edited by
                #7

                Even if this is closed I would like to comment. I have this exact problem, with OpenCV 2.4.9 and OS X Maverick. Now, I am a complete noob on the Mac, but I have worked with the unixes for a long time. The changes in the .pro file do not seem to have any change in the linking,

                @
                TEMPLATE = app
                CONFIG += console
                CONFIG -= app_bundle
                CONFIG -= qt

                SOURCES += main.cpp

                INCLUDEPATH += /usr/local/include\

                LIBS += -L/usr/local/lib
                -lopencv_core
                -lopencv_imgproc
                -lopencv_features2d
                -lopencv_highgui
                @

                I had thought that maybe the highgui libraries had not been compiled, but using the command line works:

                gcc main.cpp -L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_features2d -lopencv_highgui -lstdc++ -o planar

                Any thoughts?

                [edit: added missing coding tags @ SGaist]

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @INCLUDEPATH += /usr/local/include\ <- that backslash is wrong and probably breaks the rest of the pro file@

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    jorgeimp
                    wrote on last edited by
                    #9

                    Sorry that was a formatting error. But I found what the problem is, al I needed was to use c++11 in the configuration by adding

                    @CONFIG += c++11@

                    to the .pro file.

                    [edit: corrected formatting, SGaist]

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved