Setting up OpenCV in QT on OSX

后端 未结 3 755
清歌不尽
清歌不尽 2020-12-28 23:23

I am trying to set up OpenCV to work with QT on OSX 10.7.5/MacbookPro 2.5 Ghz Intel Core 2 Duo. I\'ve seen a few related question here (How to link

相关标签:
3条回答
  • 2020-12-28 23:55

    I just stumbled over the same problem. Here is how I solved it:

    As sansuiso already suggested, the problem appears to be the C++-STD-lib you are trying to link against. You are probably trying to link libc++ (LLVM ...) but instead libstdc++ (GNU C++ ...) should be used.

    Using the Qt Creator you can add the following to your .pro-file:

    mac: CONFIG += MAC_CONFIG
    
    MAC_CONFIG {
        QMAKE_CXXFLAGS = -std=c++11 -stdlib=libstdc++ -mmacosx-version-min=10.7
        QMAKE_LFLAGS = -std=c++11 -stdlib=libstdc++ -mmacosx-version-min=10.7
    }
    

    This answer could also be interesting for your problem: https://stackoverflow.com/a/12852913/1141118

    Hope this helps!

    0 讨论(0)
  • 2020-12-29 00:08

    You are facing 2 potential issues here:

    1. first one is, on Mac platforms, depending on the compiler (clang or gcc) you will not link against the same stdc++ library (I ran into this issue while trying to get some static opencv lib working with an iOS project). However, it does not seem to be the case here since you do not have C++ errors, but it's worth checking what compiler you use in each case;
    2. second one, QtCreator is a graphical app. Thus it is not aware of your terminal-session settings. This includes the path to dynamic libraries in /usr/local. You can avoid this by different approaches: using a static opencv lib, using install_tool to change the path to the library coded in the output binary, or by using the preferences of QtCreator to set the DYLD_LIBRARY_PATH variable to something like /usr/local/lib when it runs your program.
    0 讨论(0)
  • 2020-12-29 00:15

    Just a naive mistake

    The proper declaration is:

    LIBS += -L/usr/local/lib \
         -lopencv_core \
         -lopencv_imgproc \
         -lopencv_features2d\
         -lopencv_highgui
    
    0 讨论(0)
提交回复
热议问题