【问题标题】:OpenCV undefined reference (FileStorage with vector<KeyPoint>)OpenCV 未定义参考(带有矢量<KeyPoint> 的 FileStorage)
【发布时间】:2014-02-13 07:04:03
【问题描述】:

最近一直在使用一些 OpenCV,但是我遇到了一个有趣的问题。我有一个简单的类来存储数据并将数据读写到文件中。

这里是写函数:

cv::Mat descriptors;
vector<cv::KeyPoint> keypoints;

void EventType::write(cv::FileStorage outfile) {
    outfile << "descriptorId" << descriptors;
    outfile << "keypointId" << keypoints;
}

链接时出现问题:

EventType.cpp.o: In function cv::FileStorage& cv::operator<< <std::vector<cv::KeyPoint,
    std::allocator<cv::KeyPoint> > >(cv::FileStorage&, std::vector<cv::KeyPoint,
    std::allocator<cv::KeyPoint> > const&)':
EventType.cpp:(.text+0xc99): undefined reference to `cv::write(cv::FileStorage&,
    std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&,
    std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> > const&)'

但在链接时也建议以下替代方案:

/opencv2/core/operations.hpp:2707: note: candidates are: void cv::write(cv::FileStorage&, const std::string&, int)
/opencv2/core/operations.hpp:2708: note:                 void cv::write(cv::FileStorage&, const std::string&, float)
/opencv2/core/operations.hpp:2709: note:                 void cv::write(cv::FileStorage&, const std::string&, double)
/opencv2/core/operations.hpp:2710: note:                 void cv::write(cv::FileStorage&, const std::string&, const std::string&)
/opencv2/core/operations.hpp:2787: note:                 void cv::write(cv::FileStorage&, const cv::Range&)
/opencv2/core/operations.hpp:2856: note:                 void cv::write(cv::FileStorage&, const std::string&, const cv::Range&)
/opencv2/core/operations.hpp:2902: note:                 void cv::write(cv::FileStorage&, const std::string&, const cv::Mat&)
/opencv2/core/operations.hpp:2903: note:                 void cv::write(cv::FileStorage&, const std::string&, const cv::SparseMat&)
/opencv2/features2d/features2d.hpp:112: note:                 void cv::write(cv::FileStorage&, const std::string&, const std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> >&)

在我看来/opencv2/features2d/features2d.hpp 中的原型是完美的匹配。有什么建议吗?

【问题讨论】:

    标签: c++ opencv linker cmake


    【解决方案1】:

    如果链接器显示“未定义的引用”,则编译步骤已经完成,这意味着编译器将您的函数视为有效。

    尝试链接所有的 opencv 库,看看是否会改变结果。还要检查您使用的标头是否与您尝试链接到的库具有相同的版本。

    【讨论】:

    • 谢谢,这帮助我找到了问题所在。 :)
    【解决方案2】:

    问题出在我的 FindOpenCV.cmake 文件中。未链接 features2d 库。

    【讨论】:

      猜你喜欢
      • 2013-01-16
      • 2015-01-14
      • 2012-05-23
      • 2017-05-14
      • 2012-04-15
      • 1970-01-01
      • 2014-11-10
      • 2017-02-02
      • 1970-01-01
      相关资源
      最近更新 更多