Reputation: 33
Been working with some OpenCV recently, however I have run across an interesting problem. I have a simple class to store data and read and write the data to a file.
Here is the write function:
cv::Mat descriptors;
vector<cv::KeyPoint> keypoints;
void EventType::write(cv::FileStorage outfile) {
outfile << "descriptorId" << descriptors;
outfile << "keypointId" << keypoints;
}
The issue arrises while linking:
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&)'
However also when linking it suggests the following alternatives:
/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> >&)
It appears to me that the prototype in /opencv2/features2d/features2d.hpp
is a perfect match. Any suggestions?
Upvotes: 0
Views: 3824
Reputation: 33
The issue was in my FindOpenCV.cmake file. The features2d library was not being linked.
Upvotes: -1
Reputation: 211
If the linker says "undefined reference to" the compilation step is already done, which means the compiler accepted your function as valid.
Try linking all the opencv libraries and see if that changes the result. Also check that the headers you are using have the same version as the library you are trying to link to.
Upvotes: 2