I wrap OpenCV 4.2.0 in native C++ dll with vs2019 and use dll in C++/CLI. I select the /clr and /MD option in vs2019 to wrap dll which support CLR. However, when I link the .lib and .dll file in C++/CLI. I occur the following error:
1>pch.obj : error LNK2019: 无法解析的外部符号 “public: void __cdecl cv::Mat::copySize(class cv::Mat const &)” (?copySize@Mat@cv@QEAAXAEBV12@Z),函数 “public: __cdecl cv::Mat::Mat(class cv::Mat const &)” (??0Mat@cv@QEAA@AEBV01@Z) 中引用了该符号
1>pch.obj : error LNK2019: 无法解析的外部符号 “public: void __cdecl cv::UMat::copySize(class cv::UMat const &)” (?copySize@UMat@cv@QEAAXAEBV12@Z),函数 “public: __cdecl cv::UMat::UMat(class cv::UMat const &)” (??0UMat@cv@QEAA@AEBV01@Z) 中引用了该符号
It seems like cv::Mat class doesn’t wrap compeletly. However, It don’t appear in native C++ and I can link the OpenCV .lib and dll files in C++/CLI to solve the problem. Could someone help me?
My C++ code:
#ifdef IMAGE_CLASS_DLL
#define IMAGE_CLASS_API __declspec(dllexport)
#else
#define IMAGE_CLASS_API __declspec(dllimport)
#endif
#pragma unmanaged
#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#pragma managed
#define CV_VERSION_ID CVAUX_STR(CV_MAJOR_VERSION) CVAUX_STR(CV_MINOR_VERSION) CVAUX_STR(CV_SUBMINOR_VERSION)
#ifdef _DEBUG
#define cvLib(name) "opencv_" name CV_VERSION_ID "d.lib"
#else
#define cvLib(name) "opencv_" name CV_VERSION_ID ".lib"
#endif
#ifdef _DEBUG
#pragma comment(lib, cvLib("core"))
#pragma comment(lib, cvLib("highgui"))
#pragma comment(lib, cvLib("imgcodecs"))
#pragma comment(lib, cvLib("imgproc"))
#else
#pragma comment(lib, cvLib("core"))
#pragma comment(lib, cvLib("highgui"))
#pragma comment(lib, cvLib("imgcodecs"))
#pragma comment(lib, cvLib("imgproc"))
#endif
class IMAGE_CLASS_API ImageRead {
private:
cv::Mat matImage;
public:
ImageRead();
void ReadImage(char*);
~ImageRead();
};
ImageRead::ImageRead() {
matImage = NULL;
}
void ImageRead::ReadImage(char* pcPath) {
matImage = cv::imread(pcPath);
cv::namedWindow("Image");
cv::imshow("Image", matImage);
cv::waitKey(-1);
}
ImageRead::~ImageRead() {
}