kyamagu / mexopencv

Collection and a development kit of matlab mex functions for OpenCV library
http://kyamagu.github.io/mexopencv
Other
659 stars 319 forks source link

Compile Error #57

Closed oayhan1 closed 6 years ago

oayhan1 commented 11 years ago

I expreienced errors when compilation process.I use opencv 2.4.4 matlab r2010a and visual studio 2010. What's wrong?

mex -largeArrayDims -D_SECURE_SCL=1 -I'C:\Users\oner\Desktop\mexopencv-2.4\include' -I'C:\opencv\build\include' -L'C:\opencv\build\x86\vc10\lib'  -lopencv_calib3d243 -lopencv_calib3d244 -lopencv_contrib243 -lopencv_contrib244 -lopencv_core243 -lopencv_core244 -lopencv_features2d243 -lopencv_features2d244 -lopencv_flann243 -lopencv_flann244 -lopencv_gpu243 -lopencv_gpu244 -lopencv_haartraining_engine -lopencv_highgui243 -lopencv_highgui244 -lopencv_imgproc243 -lopencv_imgproc244 -lopencv_legacy243 -lopencv_legacy244 -lopencv_ml243 -lopencv_ml244 -lopencv_nonfree243 -lopencv_nonfree244 -lopencv_objdetect243 -lopencv_objdetect244 -lopencv_photo243 -lopencv_photo244 -lopencv_stitching243 -lopencv_stitching244 -lopencv_ts243 -lopencv_ts244 -lopencv_video243 -lopencv_video244 -lopencv_videostab243 -lopencv_videostab244 -c 'C:\Users\oner\Desktop\mexopencv-2.4\src\MxArray.cpp' -outdir 'C:\Users\oner\Desktop\mexopencv-2.4\lib'
MxArray.cpp 
c:\program files (x86)\matlab\r2010a\extern\include\matrix.h(330) : error C2371: 'char16_t' : redefinition; different basic types 
        C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\yvals.h(576) : see declaration of 'char16_t' 
C:\USERS\ONER\DESKTOP\MEXOPE~1.4\SRC\MxArray.cpp(302) : warning C4344: behavior change: use of explicit template arguments results in call to 'T MxArray::at<int>(mwIndex) const' 
        with 
        [ 
            T=int 
        ] 
        but the regular function 'MxArray MxArray::at(const std::string &,mwIndex) const' is a better match 
        if you expect 'MxArray MxArray::at(const std::string &,mwIndex) const' to be called then you need to make it an explicit specialization 
C:\USERS\ONER\DESKTOP\MEXOPE~1.4\SRC\MxArray.cpp(308) : warning C4344: behavior change: use of explicit template arguments results in call to 'T MxArray::at<double>(mwIndex) const' 
        with 
        [ 
            T=double 
        ] 
        but the regular function 'MxArray MxArray::at(const std::string &,mwIndex) const' is a better match 
        if you expect 'MxArray MxArray::at(const std::string &,mwIndex) const' to be called then you need to make it an explicit specialization 
C:\USERS\ONER\DESKTOP\MEXOPE~1.4\SRC\MxArray.cpp(314) : warning C4344: behavior change: use of explicit template arguments results in call to 'T MxArray::at<bool>(mwIndex) const' 
        with 
        [ 
            T=bool 
        ] 
        but the regular function 'MxArray MxArray::at(const std::string &,mwIndex) const' is a better match 
        if you expect 'MxArray MxArray::at(const std::string &,mwIndex) const' to be called then you need to make it an explicit specialization 
C:\USERS\ONER\DESKTOP\MEXOPE~1.4\SRC\MxArray.cpp(418) : warning C4244: 'argument' : conversion from 'double' to 'float', possible loss of data 
C:\USERS\ONER\DESKTOP\MEXOPE~1.4\SRC\MxArray.cpp(418) : warning C4244: 'argument' : conversion from 'double' to 'float', possible loss of data 
C:\USERS\ONER\DESKTOP\MEXOPE~1.4\SRC\MxArray.cpp(418) : warning C4244: 'argument' : conversion from 'double' to 'float', possible loss of data 
C:\USERS\ONER\DESKTOP\MEXOPE~1.4\SRC\MxArray.cpp(428) : warning C4244: 'argument' : conversion from 'double' to 'float', possible loss of data 
C:\USERS\ONER\DESKTOP\MEXOPE~1.4\SRC\MxArray.cpp(435) : warning C4344: behavior change: use of explicit template arguments results in call to 'T MxArray::at<int>(mwIndex) const' 
        with 
        [ 
            T=int 
        ] 
        but the regular function 'MxArray MxArray::at(const std::string &,mwIndex) const' is a better match 
        if you expect 'MxArray MxArray::at(const std::string &,mwIndex) const' to be called then you need to make it an explicit specialization 

  C:\PROGRA~2\MATLAB\R2010A\BIN\MEX.PL: Error: Compile of 'C:\USERS\ONER\DESKTOP\MEXOPE~1.4\SRC\MxArray.cpp' failed. 

??? Error using ==> mex at 222
Unable to complete successfully.

Error in ==> make at 81
        if ~opts.dryrun, eval(cmd); end
kyamagu commented 11 years ago

It seems a VS2010 issue. Is your visual studio up-to-date (patches, service pack, etc.)?

http://connect.microsoft.com/VisualStudio/feedback/details/498952/vs2010-iostream-is-incompatible-with-matlab-matrix-h

amroamroamro commented 11 years ago

The same issue was reported before (#16), but the ticket somehow disappeared.. (maybe original user deleted their account?)

Anyway, I recovered the discussion using Google cache, which I quote below for the record.

Please try the suggested solutions and report if the problem is fixed


Problem with visual studio 2010

newbie19 opened this issue September 08, 2012

I tried mexopencv using Matlab 2010a, opencv 2.4.2, and visual studio 2010, then I got following problem:

MxArray.cpp
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\yvals.h(576) : error C2371: 'char16_t' : redefinition; different basic types
c:\program files\matlab\r2010a\extern\include\matrix.h(330) : see declaration of 'char16_t'

By googling I learned that this problem occurs since I used visual studio 2010. There are many suggested solutions here: http://www.mathworks.com/matlabcentral/newsreader/view_thread/281754 but I don't know how to implement it for mexopencv.

The first error happened in MxArray.cpp , but I cannot find any line that called matrix.h.

So, can somebody help me here?

amroamroamro commented September 08, 2012

What do you get when you try to compile a minimalistic MEX function?

#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
    mexPrintf("test\n");
}

Save the above in a C++ file textMEX.cpp, and compile it using mex testMEX.cpp

In case of problems, the following section found towards the end of tmwtypes.h could be the cause of your issues:

$MATLABROOT\extern\include\tmwtypes.h

/** UTF-16 character type */

#if defined(__STDC_UTF_16__) || (defined(_HAS_CHAR16_T_LANGUAGE_SUPPORT) && _HAS_CHAR16_T_LANGUAGE_SUPPORT)
typedef char16_t CHAR16_T;
#elif defined(_MSC_VER)
typedef wchar_t CHAR16_T;
#else
typedef UINT16_T CHAR16_T;
#endif

This file is included by "matrix.h" which is in turn included by "mex.h" (required by all MEX files)

(I am using R2012a on WinXP+VS2010 and I have no problems compiling)

kyamagu commented September 08, 2012

Do you install Windows SDK? You say you're using vs2010 win64 but at least your compiler seems to be x86. Make sure you're using 64-bit compiler in Matlab 64-bit and also run mex -setup to choose Win SDK for the compiler.

C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\yvals.h(576) : error C2371: 'char16_t' : redefinition; different basic types 
c:\program files\matlab\r2010a\extern\include\matrix.h(330) : see declaration of 'char16_t'

amroamroamro commented September 08, 2012

Also VS2010 was only officially supported starting at MATLAB R2010b, although there is a patch available for R2010a. Perhaps you should consider updating MATLAB if possible..

As a quick fix, try editing MxArray.hpp, and move mex.h after the other includes with:

#ifdef _CHAR16T
#define CHAR16_T
#endif
#include "mex.h"

Some more references found here and here.

kyamagu closed the issue November 07, 2012