2011-10-09 93 views
2

我正在使用XCode4和OpenCV 2.3。 我編譯了一個OpenCV的副本。這裏是.a的信息:有關Xcode中OpenCV的鏈接錯誤

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中,並設置庫搜索的正確路徑。 但是當我編譯時,它發生了這樣的錯誤:

看來,在OpenCV庫中使用的STL沒有鏈接在.a文件中。 如何解決它?

謝謝,鞠躬。符號(S)沒有發現建築的ARMv7 collect2:用於建築的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 LD返回1退出狀態

BTW:當我設置的文件名。毫米,鏈接器報告內部編譯器錯誤。總線錯誤。

+6

一個.a文件從來沒有鏈接過,你是否嘗試過把C++庫鏈接到你的可執行文件,用gcc,這將會添加-lstdC++, –

+0

大衛,你剛剛救了我一個頭痛的問題,也許這應該是一個正式的答案而不是評論,將+1作爲答案,而不是評論的+1。 – imnk

回答

1

我得到答案。

OpenCV中的MIN宏與Xcode中預定義的MIN衝突。

將.m文件重命名爲.mm,並將所有MIN函數更改爲新名稱,例如OpenCV頭文件中的CV_MIN。

檢查。

0

必應,你是正確的關於OpenCV的MIN(和MAX)宏。我必須重新命名它們,可能從2.0版開始:)

但是,沒有必要將所有.m文件重命名爲.mm文件,因爲Xcode默認處理它們的方式不同 - 是Objective-C++文件 - 想。

正如David所指出的那樣,最好鏈接std C++庫。

+0

這個問題已經有*年前*的接受答案... – alestanis

0

另一件值得一提的事情,至少在xcode 4.5中,是你必須在你的目標設置中將你的C++標準庫改爲'libstdC++'才能讓openCV編譯。

0

刪除了iOS 4.3的支持和使用「的libC++」也可能有助於

7

,您可以通過使用C++標準庫設置鏈接。 「構建階段 - >鏈接二進制與圖書館」

enter image description here