opencv2/opencv.hpp file not found in Xcode

前端 未结 9 2047
悲哀的现实
悲哀的现实 2020-12-30 10:14

I have built openCV to get opencv2.framework. I added this to my xcode iOS project by going to \"build phases->Link Binary With Libraries\", then tried to include \"opencv2

相关标签:
9条回答
  • 2020-12-30 10:39

    I used openCV in my project and implementing it with cocoapods was impossible because version of library was too old, so i decided to implement it as static library. create folder in your project and add library there, in build settings find library and framework search path and add link to your openCV folder. It will work without any error. Also you should add openCV header file in prefixPatch.

    More Detail Instruction 100% Works:

    1) Download framework from official website: OpenCV

    2) In Project Directory create folder named: External_SDK

    3) Put Opencv framework inside this folder and drag&drop it in Xcode Project (Folder) with Target Membership of your App (Not App_test).

    4) In Xcode Project search for yourPrefixHeaderFileName.pch and in the top of the file add this lines:

    #ifdef __cplusplus
    #import <opencv2/opencv.hpp>
    #endif
    

    5) after that you should import or include it in .h file, why include? because it's CPP library. If you want to access library with import keywoard than you should do like this: #import <EXAMPLE>

    6) In build settings search for library and framework search path and add link to your EXTERNAL_SDK folder. To read framework directly from your folder. Find and change ALWAYS_SEARCH_USER_PATHS = YES and in HEADER_SEARCH_PATHS add $(inherited) and /usr/include/FRAMEWORK_PATH

    Hope this answer will help someone.

    And the best practice is to call

    #include <opencv2/highgui/highgui.hpp>
    #include <opencv2/core/core.hpp>
    

    Only header files.

    0 讨论(0)
  • 2020-12-30 10:46

    I solve the problem by adding to the FRAMEWORK_SEARCH_PATHS the absolute path were I had the framework I needed to use:

    You should use your own path obviously. ;-)

    0 讨论(0)
  • 2020-12-30 10:46

    I ran into some issues when I went to Target-->Build Phases-->Link Binary With Libraries. When I added opencv2.framework from there, my app would not launch.

    Instead, I just dragged and dropped the framework under the directory "Frameworks" in XCode and that worked. I didn't change anything else.

    0 讨论(0)
提交回复
热议问题