打开CV: CV::LineIterator在编译Mac M1时未定义



我有一个错误的Undefined symbol cv::LineIterator::LineIterator(cv::Mat const&, cv::Point_<int>, cv::Point_<int>, int, bool)。所以我偶然发现了这个问题,我不确定它是否是一个bug,但我不知道如何修复它或我做错了什么。

我正在尝试编译一个使用OpenCV 4.5.1的库,我自己为Mac Catalyst架构编译了这个库。我为arm64和x86_64体系结构编译的OpenCV库

$ lipo -info opencv2macos.framework/opencv2macos
Architectures in the fat file: opencv2macos.framework/opencv2macos are: x86_64 arm64

然而,当我试图编译一个实例化cv::LineIterator line_it(mask, cv::Point(2, 4), cv::Point(10, 20), 8, false)的库时,我得到这个错误:

Undefined symbols for architecture arm64:
"cv::LineIterator::LineIterator(cv::Mat const&, cv::Point_<int>, cv::Point_<int>, int, bool)", referenced from:
getPointCorresp(Eigen::Matrix<double, 3, 1, 0, 3, 1> const&, Eigen::Matrix<double, 3, 1, 0, 3, 1> const&, cv::Mat const&, std::__1::vector<cv::Point_<float>, std::__1::allocator<cv::Point_<float> > > const&, cv::Mat const&, bool) in CMAUtil.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

你知道这里出了什么问题吗?

经过更多的研究和调查,问题是因为我使用了两个opencv2框架,一个为iOS设备编译,一个为Mac Catalyst编译。

当我为Catalyst编译框架时,我使用一个标志将框架的名称从opencv2更改为opencv2macos,这意味着包含头应该像#include<opencv2macos/core.hpp>一样。然而,当我看到更多的头,我可以找到#include<opencv2/imgproc.hpp>,这解释了为什么我的项目以某种方式链接到错误的框架-它链接到opencv2.framework而不是opencv2macos.framework的代码,因为这两个是不同的版本(第一个是4.1.1,第二个是4.5.1),我猜在实现中存在差异。

最新更新