9
votes

I've got the precompiled opencv2.framework from OpenCV, and I've added it to my project. However trying to compile the project gives errors like:

Undefined symbols for architecture armv7:
  "std::__1::__vector_base_common<true>::__throw_length_error() const", referenced from:
      std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >::__append(unsigned long) in opencv2(matrix.o)
      std::__1::vector<cv::Vec<int, 128>, std::__1::allocator<cv::Vec<int, 128> > >::__append(unsigned long) in opencv2(matrix.o)
      std::__1::vector<cv::Vec<int, 64>, std::__1::allocator<cv::Vec<int, 64> > >::__append(unsigned long) in opencv2(matrix.o)
      std::__1::vector<cv::Vec<int, 32>, std::__1::allocator<cv::Vec<int, 32> > >::__append(unsigned long) in opencv2(matrix.o)
      std::__1::vector<cv::Vec<int, 16>, std::__1::allocator<cv::Vec<int, 16> > >::__append(unsigned long) in opencv2(matrix.o)
      std::__1::vector<cv::Vec<int, 12>, std::__1::allocator<cv::Vec<int, 12> > >::__append(unsigned long) in opencv2(matrix.o)
      std::__1::vector<cv::Vec<int, 9>, std::__1::allocator<cv::Vec<int, 9> > >::__append(unsigned long) in opencv2(matrix.o)
      ...
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      cv::Exception::Exception(int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int) in opencv2(system.o)
      cv::error(cv::Exception const&) in opencv2(system.o)
      _cvRegisterModule in opencv2(system.o)
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::operator=(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      cv::Exception::formatMessage() in opencv2(system.o)
  "_OBJC_CLASS_$_ALAssetsLibrary", referenced from:
      objc-class-ref in opencv2(cap_ios_video_camera.o)
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init(char const*, unsigned long)", referenced from:
      cv::sum(cv::_InputArray const&) in opencv2(stat.o)
      cv::countNonZero(cv::_InputArray const&) in opencv2(stat.o)
      cv::mean(cv::_InputArray const&, cv::_InputArray const&) in opencv2(stat.o)
      cv::meanStdDev(cv::_InputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, cv::_InputArray const&) in opencv2(stat.o)
      cv::minMaxIdx(cv::_InputArray const&, double*, double*, int*, int*, cv::_InputArray const&) in opencv2(stat.o)
      cv::minMaxLoc(cv::_InputArray const&, double*, double*, cv::Point_<int>*, cv::Point_<int>*, cv::_InputArray const&) in opencv2(stat.o)
      cv::norm(cv::_InputArray const&, int, cv::_InputArray const&) in opencv2(stat.o)
      ...
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()", referenced from:
      cv::sum(cv::_InputArray const&) in opencv2(stat.o)
      cv::countNonZero(cv::_InputArray const&) in opencv2(stat.o)
      cv::mean(cv::_InputArray const&, cv::_InputArray const&) in opencv2(stat.o)
      cv::meanStdDev(cv::_InputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, cv::_InputArray const&) in opencv2(stat.o)
      cv::minMaxIdx(cv::_InputArray const&, double*, double*, int*, int*, cv::_InputArray const&) in opencv2(stat.o)
      cv::minMaxLoc(cv::_InputArray const&, double*, double*, cv::Point_<int>*, cv::Point_<int>*, cv::_InputArray const&) in opencv2(stat.o)
      cv::norm(cv::_InputArray const&, int, cv::_InputArray const&) in opencv2(stat.o)
      ...
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I've set Build Active Architectures Only to No in my build settings, but it still happens. What do I need to do to get OpenCV working? I'm using XCode 5, targeting iOS7.

I've already added -lstdc++ to linker flags and switch the C++ compiler to libstdc++, as-per this answer.

I have tried compiling OpenCV from source too but that yields the same error.

It's the same regardless of whether I have iOS6 or 7 as the deployment target.

1
Did you ever find the solution?aledalgrande

1 Answers

17
votes

Two things you should check:

  1. You're attempting to use the C++ portions of OpenCV but Xcode/clang are very literal. If the file you're linking with is a .m it'll treat it as an Objective-C. Instead we want to treat it as an Objective-C++ file by either renaming the extension to .mm or by bringing up the file's properties in the right side bar and selecting Objective-C++ Source for the Type.

  2. ALAssetsLibrary is defined in AssetsLibrary.framework, please add it to your Link Binary With Libraries step for your project.