使用 OpenCV 中的 Featured2D 和 XCode 构建错误

Build error using Featured2D in OpenCV with XCode

本文关键字:XCode 构建 错误 Featured2D OpenCV 中的 使用      更新时间:2023-10-16

在OpenCV中使用Features2D时,我一直在与构建错误作斗争,我不知道为什么。

  • OpenCV 版本: 2.4.3 (MacPorts)
  • 编译架构:64位英特尔
  • C 语言方言:GNU99
  • C++ 语言方言:GNU++11
  • C++ 标准库:libstdc++

构建错误:

Undefined symbols for architecture x86_64:
"cv::FeatureDetector::detect(cv::Mat const&, std::__debug::vector<cv::KeyPoint,     std::allocator<cv::KeyPoint> >&, cv::Mat const&) const", referenced from:
  analysis::openCvStitching() in analysis.o
"cv::DescriptorMatcher::match(cv::Mat const&, cv::Mat const&, std::__debug::vector<cv::DMatch, std::allocator<cv::DMatch> >&, cv::Mat const&) const", referenced from:
  analysis::openCvStitching() in analysis.o
"cv::DescriptorExtractor::compute(cv::Mat const&, std::__debug::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> >&, cv::Mat&) const", referenced from:
  analysis::openCvStitching() in analysis.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

这就是我创建指向 FeatureDetector 和 DescriptorExtractor 的指针的方式:

Ptr<FeatureDetector> surfDetector = FeatureDetector::create(type);
Ptr<DescriptorExtractor> surfExtractor = DescriptorExtractor::create(type);

您是否尝试过从项目设置中的预处理器标志中删除_GLIBCXX_DEBUG=1和/或_GLIBCXX_DEBUG_PEDANTIC=1? OpenCV2 C++ API 在 API 函数中使用 STL 模板时有些糟糕,如果标准库或编译器标志的版本与编译时使用的版本不完全匹配,则可能会导致链接器错误或崩溃。