Thanks for your answer. My goal is to wrap OpenCV in another library, let’s call it libdetector.
The wrapper code looks like this (it doesn’t do anything useful yet, just for illustration)
detector.cc
#include "detector.hh"
#include <string>
#include <vector>
#include "opencv2/opencv.hpp"
#include "opencv2/videoio.hpp"
namespace detector {
Detector::Detector(const std::string& filepath) : filepath(filepath) {}
std::vector<float> Detector::detect(float similarityThreshold) {
cv::Mat new_img = cv::Mat::zeros(1, 49, CV_64FC1);
std::vector<float> vec{1.0, 1.0, 1.0};
return vec;
}
} // namespace detector
detector.hh
#ifndef DETECTOR_H
#define DETECTOR_H
#include <string>
#include <vector>
#include "opencv2/opencv.hpp"
#include "opencv2/videoio.hpp"
namespace detector {
class Detector {
private:
std::string filepath;
public:
Detector(const std::string &filepath);
std::vector<float> detect(float similarityThreshold = 0.7);
};
} // namespace detector
#endif
If I now compile this to a shared library with
g++ -Wl,--no-undefined -fPIC -shared -o libdetector.so detector.cc opencv/lib/libopencv_highgui.a opencv/lib/libopencv_videoio.a opencv/lib/libopencv_imgproc.a opencv/lib/libopencv_core.a opencv/3rdparty/lib/*.a opencv/3rdparty/ippicv/ippicv_lnx/icv/lib/intel64/libippicv.a -ldl -lpthread -lz
I get undefined reference to cv::String::deallocate()
If I’d just add the definition
namespace cv {
void String::deallocate(){};
}
to my detector.cc source, it works as expected. So for some reason the linker can’t find the cv::String::deallocate() symbol in the OpenCV libraries.