我从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>, 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)
我在构建设置中将仅构建活动架构设置为否,但它仍然会发生。我需要做些什么才能让OpenCV正常工作?我使用的是XCode 5,目标是iOS7。
我已经added -lstdc++
to linker flags and switch the C++ compiler to libstdc++, as-per this answer。
我也尝试过从源代码编译OpenCV,但会产生同样的错误。
无论我是否将iOS6或7作为部署目标,它都是一样的。
答案 0 :(得分:17)
你应该检查两件事:
您正在尝试使用OpenCV的C ++部分,但Xcode / clang非常直观。如果您要链接的文件是.m
,则会将其视为Objective-C。相反,我们希望通过将扩展名重命名为.mm
或者在右侧栏中显示文件属性并为类型选择Objective-C++ Source
来将其视为Objective-C ++文件。强>
ALAssetsLibrary
在AssetsLibrary.framework
中定义,请将其添加到您项目的 Link Binary With Libraries 步骤中。