开发者

Link Error about OpenCV in Xcode

开发者 https://www.devze.com 2023-04-11 13:13 出处:网络
I am using XCode4 and OpenCV 2.3. I have compiled a copy of OpenCV. Here is the .a\'s info: libopencv_core.a: Mach-O universal binary with 3 architectures

I am using XCode4 and OpenCV 2.3. I have compiled a copy of OpenCV. Here is the .a's info:

libopencv_core.a: Mach-O universal binary with 3 architectures
libopencv_core.a (for architecture armv7):  current ar archive random library
libopencv_core.a (for architecture armv6):  current ar archive random library
libopencv_core.a (for architecture i386):   current ar archive random library

I drag it to the Frameworks floder, and set the right path of library search. But when I compiled, it occurred such errors:

It seems that the STL which is used in OpenCV lib was not linked in the .a file. How to fix it?

Thanks, bow.

Undefined symbols for architecture armv7:

"___cxa_begin_catch", referenced from:
      icvReadSeq(CvFileStorage*, CvFileNode*)       in libopencv_cor开发者_运维技巧e.a(persistence.o)
  "typeinfo for std::exception", referenced from:
      typeinfo for cv::Exceptionin libopencv_core.a(alloc.o)
  "operator delete(void*)", referenced from:
      cv::Exception::~Exception()in libopencv_core.a(alloc.o)
  "_gzputs", referenced from:
      icvPuts(CvFileStorage*, char const*)in libopencv_core.a(persistence.o)
  "std::basic_string<char, std::char_traits<char>, std::allocator<char> >::_Rep::_M_destroy(std::allocator<char> const&)", referenced from:
      cv::OutOfMemoryError(unsigned long)in libopencv_core.a(alloc.o)
      cv::Exception::~Exception()in libopencv_core.a(alloc.o)
      cv::Exception::~Exception()in libopencv_core.a(alloc.o)
      _cvCreateMatHeader in libopencv_core.a(array.o)
      _cvGetImageCOI in libopencv_core.a(array.o)
      _cvSetImageCOI in libopencv_core.a(array.o)
      _cvGetSize in libopencv_core.a(array.o)
      ...
  "std::basic_string<char, std::char_traits<char>, std::allocator<char> >::assign(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
      cv::OutOfMemoryError(unsigned long)in libopencv_core.a(alloc.o)
      cv::Exception::Exception(int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)in libopencv_core.a(array.o)
      _cvRegisterModule in libopencv_core.a(system.o)
  "___cxa_throw", referenced from:
      cv::error(cv::Exception const&)in libopencv_core.a(system.o)
  "___cxa_end_catch", referenced from:
      icvReadSeq(CvFileStorage*, CvFileNode*)       in libopencv_core.a(persistence.o)
  "_cvCvtColor", referenced from:
      -[cviosViewController CreateIplImageFromUIImage:] in cviosViewController.o
  "vtable for std::exception", referenced from:
      cv::Exception::Exception(int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)in libopencv_core.a(array.o)
      cv::error(cv::Exception const&)in libopencv_core.a(system.o)
  "operator new[](unsigned long)", referenced from:
      cv::mixChannels(cv::Mat const*, unsigned long, cv::Mat*, unsigned long, int const*, unsigned long)in libopencv_core.a(convert.o)
  "std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
      cv::OutOfMemoryError(unsigned long)in libopencv_core.a(alloc.o)
      cv::Exception::Exception(int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)in libopencv_core.a(array.o)
      cv::error(cv::Exception const&)in libopencv_core.a(system.o)
      _cvRegisterModule in libopencv_core.a(system.o)
  "vtable for __cxxabiv1::__si_class_type_info", referenced from:
      typeinfo for cv::Exceptionin libopencv_core.a(alloc.o)
  "std::terminate()", referenced from:
      cv::error(cv::Exception const&)in libopencv_core.a(system.o)
  "___cxa_allocate_exception", referenced from:
      cv::error(cv::Exception const&)in libopencv_core.a(system.o)
  "___gxx_personality_sj0", referenced from:
      cv::OutOfMemoryError(unsigned long)in libopencv_core.a(alloc.o)
      _cvCreateMatHeader in libopencv_core.a(array.o)
      _cvGetImageCOI in libopencv_core.a(array.o)
      _cvSetImageCOI in libopencv_core.a(array.o)
      _cvGetSize in libopencv_core.a(array.o)
      _cvGetDims in libopencv_core.a(array.o)
      _cvGetElemType in libopencv_core.a(array.o)
      ...
  "std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)", referenced from:
      cv::OutOfMemoryError(unsigned long)in libopencv_core.a(alloc.o)
      _cvCreateMatHeader in libopencv_core.a(array.o)
      _cvGetImageCOI in libopencv_core.a(array.o)
      _cvSetImageCOI in libopencv_core.a(array.o)
      _cvGetSize in libopencv_core.a(array.o)
      _cvGetDims in libopencv_core.a(array.o)
      _cvGetElemType in libopencv_core.a(array.o)
      ...
  "operator delete[](void*)", referenced from:
      cv::mixChannels(cv::Mat const*, unsigned long, cv::Mat*, unsigned long, int const*, unsigned long)in libopencv_core.a(convert.o)
  "std::basic_string<char, std::char_traits<char>, std::allocator<char> >::_Rep::_S_empty_rep_storage", referenced from:
      cv::OutOfMemoryError(unsigned long)in libopencv_core.a(alloc.o)
      cv::Exception::~Exception()in libopencv_core.a(alloc.o)
      cv::Exception::~Exception()in libopencv_core.a(alloc.o)
      _cvCreateMatHeader in libopencv_core.a(array.o)
      _cvGetImageCOI in libopencv_core.a(array.o)
      _cvSetImageCOI in libopencv_core.a(array.o)
      _cvGetSize in libopencv_core.a(array.o)
      ...
  "std::exception::~exception()", referenced from:
      cv::OutOfMemoryError(unsigned long)in libopencv_core.a(alloc.o)
      cv::Exception::~Exception()in libopencv_core.a(alloc.o)
      cv::Exception::~Exception()in libopencv_core.a(alloc.o)
      cv::Exception::Exception(int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)in libopencv_core.a(array.o)
      cv::error(cv::Exception const&)in libopencv_core.a(system.o)
      _cvRegisterModule in libopencv_core.a(system.o)

ld: symbol(s) not found for architecture armv7 collect2: ld returned 1 exit status

BTW: When I set the file name to .mm, the linker reports Internal Complier error. Bus error.


You can setup link with c++ standard library via "Build Phases -> Link Binary With Libraries"

Link Error about OpenCV in Xcode


I get the answer.

The MIN macro in OpenCV is conflict with MIN predefined in Xcode.

Rename .m files to .mm, and change all MIN function to a new name such as CV_MIN in OpenCV's header files.

Check.


Bing, you are correct about the OpenCV's MIN (and MAX) macros. I have to rename them probably since v 2.0 :)

However, it's not necessary to rename all .m files to .mm files since Xcode treats them differently by default - being Objective-C++ files - which is not always what you want.

It's better to link std c++ library, as David pointed out above.


Another thing worth mentioning, at least in xcode 4.5, is that you have to change your C++ standard library to 'libstdc++' in your target settings to get openCV to compile.


Dropping the iOS 4.3 support and using the "libc++' might also help.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号