我从OpenCV获得了
precompiled opencv2.framework,我已将它添加到我的项目中.但是,尝试编译项目会产生以下错误:
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>,64> > >::__append(unsigned long) in opencv2(matrix.o) std::__1::vector<cv::Vec<int,32>,32> > >::__append(unsigned long) in opencv2(matrix.o) std::__1::vector<cv::Vec<int,16>,16> > >::__append(unsigned long) in opencv2(matrix.o) std::__1::vector<cv::Vec<int,12>,12> > >::__append(unsigned long) in opencv2(matrix.o) std::__1::vector<cv::Vec<int,9>,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::allocator<char> > const&)",referenced from: cv::Exception::Exception(int,std::__1::basic_string<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::allocator<char> >::operator=(std::__1::basic_string<char,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::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::_InputArray const&) in opencv2(stat.o) cv::minMaxIdx(cv::_InputArray const&,double*,int*,cv::_InputArray const&) in opencv2(stat.o) cv::minMaxLoc(cv::_InputArray const&,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::allocator<char> >::~basic_string()",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)
我在构建设置中仅将Build Active Architectures设置为No,但它仍然会发生.我需要做些什么才能让OpenCV正常工作?我正在使用XCode 5,目标是iOS7.
我已经added -lstdc++
to linker flags and switch the C++ compiler to libstdc++,as-per this answer了.
无论我是否将iOS6或7作为部署目标,它都是一样的.
解决方法
@H_404_15@ 你应该检查两件事:>您正在尝试使用OpenCV的C部分,但Xcode / clang非常直观.如果您要链接的文件是.m,它会将其视为Objective-C.相反,我们希望通过将扩展名重命名为.mm或者在右侧栏中显示文件属性并为类型选择Objective-C Source来将其视为Objective-C文件.> ALAssetsLibrary在AssetsLibrary.framework中定义,请将其添加到项目的Link Binary With Libraries步骤中.