Hi, I’m trying to learn how to define my own opencv extra module and build it out of the sources folder. I have write a simple test code and I meet some link error while building on window’s msvc :
[Edit]: error log text version:
20>matlib.obj : error LNK2019: 在函式 "public: class cv::Mat __cdecl cv::_InputArray::getMat_(int)const " (?getMat_@_InputArray@cv@@QEBA?AVMat@2@H@Z)"public: void __cdecl cv::matlib::transform::Inc(class cv::_InputArray const &,class cv::_OutputArray const &)" (?Inc@transform@matlib@cv@@QEAAXAEBV_InputArray@3@AEBV_OutputArray@3@@Z) 中參考了無法解析的外部符號
20>opencv_matlib_pch.obj : error LNK2001: 無法解析的外部符號 "public: class cv::Mat __cdecl cv::_InputArray::getMat_(int)const " (?getMat_@_InputArray@cv@@QEBA?AVMat@2@H@Z)
20>matlib.obj : error LNK2019: 在函式 "public: enum cv::_InputArray::KindFlag __cdecl cv::_InputArray::kind(void)const " (?kind@_InputArray@cv@@QEBA?AW4KindFlag@12@XZ)"public: void __cdecl cv::matlib::transform::Inc(class cv::_InputArray const &,class cv::_OutputArray const &)"
The chinese “無法解析的外部符號” is equal to [ unresolved external symbol]
I try to build this extra module(matlib.cpp) with opencv source in: F:/opencv-master with CMakeLists.txt:
set(the_description "matlib module")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR})
SET(CMAKE_CXX_FLAGS "/O2")
include_directories(F:/opencv-master/modules/core/include)
include_directories(./include)
set(MODEL_SRCS matlib.cpp)
ocv_glob_module_sources(${MODEL_SRCS})
ocv_define_module(matlib WRAP python)
When I run OpenCV.sln and build the ALL_BUILD I meet the link error above. I know I should add some .lib path or include path in mscv settings but I don’t know which one causing the error. Any Idea?
My custom module:
matlib.cpp:
#include "precomp.hpp"
#include <iostream>
namespace cv {
namespace matlib {
void transform::Inc(InputArray src, OutputArray dst)
{
cv::Mat M = src.getMat();
int image_width = M.cols;
int image_height = M.rows;
std::cout << "arr in c++: " << std::endl << " " << M << std::endl << std::endl;
for(int i = 0; i < M.rows; i++)
{
double* Mi = M.ptr<double>(i);
for(int j = 0; j < M.cols; j++)
Mi[j] = Mi[j] + 1;
}
M.copyTo(dst);
}
} // Matlib
} // cv
matlib.hpp:
#ifndef __OPENCV_matlib_HPP__
#define __OPENCV_matlib_HPP__
#include "opencv2/core.hpp"
namespace cv {
namespace matlib {
class CV_EXPORTS_W transform
{
public:
CV_WRAP transform() {}
virtual ~transform() {}
CV_WRAP void Inc(InputArray src, OutputArray dst);
};
} // matlib
} // cv
#endif