Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Compiling VS2017 CLR Project with OpenCV 3.4.1

Hi,

I created a Console project in VS2017 utilizing OpenCV 3.4.1 and it worked as intended (include, bin, lib directories and no CLR).

However, now I'm trying to call these functions from another application and I need to compile the .dll with metadata to provide interoperability, thus hinting I need to recompile with /CLR.

The OpenCV cvdef.h file sets CV_CXX_STD_ARRAY=1 if you're in VS2017 or C++11 compiler, which adds #include <array>. This seems to be loading a different variant of array from mscorlib (added to References when you enable CLR) instead of stdlib, which is now breaking compilation.

...
#ifndef CV_CXX_STD_ARRAY
# if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900/*MSVS2015*)
#  define CV_CXX_STD_ARRAY 1
#  include <array>
# endif
...

The errors I'm receiving are for mat.inl.hpp line 1947:

#ifdef CV_CXX_STD_ARRAY
template<typename _Tp> template<std::size_t _Nm> inline
Mat_<_Tp>::operator std::array<_Tp, _Nm>() const [<-- line 1947]
{
   std::array<_Tp, _Nm> a;
   copyTo(a);
   return a;
}

C3149: 'cli::array<_Tp,_Nm>': cannot use this type here without a top-level '^'
C2244: 'cv::Mat_<_Tp>::operator cli::array<_Tp,_Nm> ^': unable to match function definition to an existing declaration

I think C2244 is triggered when the compiler makes the suggested edit for C3149, thus saying it doesn't have a definition for array<_Tp,_Nm>^

Any advice or suggested edits?

EDIT:

I don't like this solution, but I can get the CLR .dll to compile by commenting out the cvdef.h lines:

...
#ifndef CV_CXX_STD_ARRAY
# if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900/*MSVS2015*)
#  //define CV_CXX_STD_ARRAY 1
#  //include <array>
# endif
...