Search code examples
iosxcodeopencvxcode4.5

error after compiling opencv2.4.3 on ios


I have been facing the problems below when compiling an application on xcode for iOS after using the framework 2.4.3 from official opencv.org. Any clues?

ld: warning: directory not found for option '-F/Users/Anas/Downloads/ocr-text-extraction-master  /n/trunk/StaticImagesFaceDetectionSample/../../ocv.build/ios'
Undefined symbols for architecture armv7:
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::compare(char const*) const", referenced from:
  cv::CascadeClassifier::Data::read(cv::FileNode const&) in opencv2(cascadedetect.o)
 ...
 ...

 ...

 cv::Exception::formatMessage() in opencv2(system.o)
 ld: symbol(s) not found for architecture armv7
 clang: error: linker command failed with exit code 1 (use -v to see invocation)

Solution

  • Are you using the universal iOS framework provided by OpenCV?

    If not, I strongly suggest you to use it: OpenCV for iOS. Just download it, drop it into your iOS project and add import it.

    You can also add this inside your myApp-Prefix.pch to import OpenCV in every C++ compatible source file (.mm, .cpp):

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

    EDIT

    Also make sure that opencv2.framework is added to the target you're building. To add it to the target, open up the right side menu in Xcode (Utilities) while opencv2.framework is selected. There is a dropdown in the File Inspector called "Target Membership". If you select that, it will add the framework to the target.

    EDIT 2

    Another thing to make sure is importing the right headers to use cv::CascadeClassifier:

    #import <opencv2/imgproc/imgproc_c.h>
    #import <opencv2/objdetect/objdetect.hpp>