在Xcode中关于OpenCV的链接错误

我正在使用XCode4和OpenCV 2.3。 我已经编译了一个OpenCV的副本。 这里是.a的信息:

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 

我把它拖到Frameworks floder中,并设置库search的正确path。 但是当我编译时,发生了这样的错误:

看来在OpenCV库中使用的STL没有链接在.a文件中。 如何解决它?

谢谢,弓。

未定义的符号为build筑armv7:

 "___cxa_begin_catch", referenced from: icvReadSeq(CvFileStorage*, CvFileNode*) in libopencv_core.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:符号(s)找不到架构armv7 collect2:ld返回1退出状态

顺便说一句:当我将文件名称设置为.mm,链接器报告内部编译器错误。 总线错误。

您可以通过“Build Phases – > Link Binary With Libraries”设置与c ++标准库的链接。

在这里输入图像说明

我得到答案。

OpenCV中的MINmacros与Xcode中预定义的MIN冲突。

将.m文件重命名为.mm,并将所有MIN函数更改为新名称,例如OpenCV头文件中的CV_MIN。

检查。

Bing,你对OpenCV的MIN(和MAX)macros是正确的。 我必须重新命名他们可能从2.0版以来:)

但是,没有必要将所有.m文件重命名为.mm文件,因为Xcode默认处理它们的方式不同 – 是Objective-C ++文件 – 这并不总是您想要的。

正如David所指出的,链接std c ++库更好。

另外值得一提的是,至less在xcode 4.5中,你必须在你的目标设置中将你的C ++标准库改为“libstdc ++”来获得openCV的编译。

删除iOS 4.3的支持,并使用“libc ++”也可能有所帮助。