How to solve this error presented when compiling .cpp files to mex?
Show older comments
I have been attempting to solve this error but I could not found the root of the problem. I am using Matlab 2018a, windows 10 at x64. I installed manueally the MinGW64 Compiler version 5.3.0. I would appreciatte very much a hand of the community in this task. Thank you
mex -v imgcut3.cpp
Verbose mode is on.
... Looking for compiler 'MinGW64 Compiler (C++)' ...
... Looking for environment variable 'MW_MINGW64_LOC' ...Yes ('C:\x86_64-5.3.0-release-posix-seh-rt_v4-rev0\mingw64').
... Looking for file 'C:\x86_64-5.3.0-release-posix-seh-rt_v4-rev0\mingw64\bin\g++.exe' ...Yes.
... Looking for folder 'C:\x86_64-5.3.0-release-posix-seh-rt_v4-rev0\mingw64' ...Yes.
... Looking for environment variable 'MW_MINGW64_LOC' ...Yes ('C:\x86_64-5.3.0-release-posix-seh-rt_v4-rev0\mingw64').
... Executing command 'C:\x86_64-5.3.0-release-posix-seh-rt_v4-rev0\mingw64\bin\g++ -dumpmachine' ...Yes ('x86_64-w64-mingw32').
Found installed compiler 'MinGW64 Compiler (C++)'.
Set PATH = C:\x86_64-5.3.0-release-posix-seh-rt_v4-rev0\mingw64\bin;C:\Program Files\MATLAB\R2018a\extern\include\win64;C:\Program Files\MATLAB\R2018a\extern\include;C:\Program Files\MATLAB\R2018a\simulink\include;C:\Program Files\MATLAB\R2018a\lib\win64;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\MATLAB\R2018a\runtime\win64;C:\Program Files\MATLAB\R2018a\bin;C:\TDM-GCC-64\bin;C:\Users\DAVID\AppData\Local\Microsoft\WindowsApps;;C:\Program Files\Mozilla Firefox
Set INCLUDE = C:\x86_64-5.3.0-release-posix-seh-rt_v4-rev0\mingw64\include;C:\x86_64-5.3.0-release-posix-seh-rt_v4-rev0\mingw64\x86_64-w64-mingw32\include\c++;C:\x86_64-5.3.0-release-posix-seh-rt_v4-rev0\mingw64\x86_64-w64-mingw32\include;C:\x86_64-5.3.0-release-posix-seh-rt_v4-rev0\mingw64\x86_64-w64-mingw32\include\c++\x86_64-w64-mingw32;C:\x86_64-5.3.0-release-posix-seh-rt_v4-rev0\mingw64\x86_64-w64-mingw32\include\c++\backward;C:\x86_64-5.3.0-release-posix-seh-rt_v4-rev0\mingw64\include;C:\x86_64-5.3.0-release-posix-seh-rt_v4-rev0\mingw64\x86_64-w64-mingw32\include\c++;C:\x86_64-5.3.0-release-posix-seh-rt_v4-rev0\mingw64\x86_64-w64-mingw32\include;C:\x86_64-5.3.0-release-posix-seh-rt_v4-rev0\mingw64\x86_64-w64-mingw32\include\c++\x86_64-w64-mingw32;C:\x86_64-5.3.0-release-posix-seh-rt_v4-rev0\mingw64\x86_64-w64-mingw32\include\c++\backward;
Set LIB = C:\x86_64-5.3.0-release-posix-seh-rt_v4-rev0\mingw64\lib;;C:\x86_64-5.3.0-release-posix-seh-rt_v4-rev0\mingw64\lib;;
Set MW_TARGET_ARCH = win64;win64;
Set LIBPATH = C:\Program Files\MATLAB\R2018a\extern\lib\win64;C:\Program Files\MATLAB\R2018a\extern\lib\win64;
Options file details
-------------------------------------------------------------------
Compiler location: C:\x86_64-5.3.0-release-posix-seh-rt_v4-rev0\mingw64
Options file: C:\Users\DAVID\AppData\Roaming\MathWorks\MATLAB\R2018a\mex_C++_win64.xml
CMDLINE2 : C:\x86_64-5.3.0-release-posix-seh-rt_v4-rev0\mingw64\bin\g++ -m64 -Wl,--no-undefined -shared -static -s -Wl,"C:\Program Files\MATLAB\R2018a/extern/lib/win64/mingw64/exportsmexfileversion.def" C:\Users\DAVID\AppData\Local\Temp\mex_192127030071693_10192\imgcut3.obj C:\Users\DAVID\AppData\Local\Temp\mex_192127030071693_10192\cpp_mexapi_version.obj -L"C:\Program Files\MATLAB\R2018a\extern\lib\win64\mingw64" -llibmx -llibmex -llibmat -lm -llibmwlapack -llibmwblas -llibMatlabDataArray -llibMatlabEngine -o imgcut3.mexw64
CXX : C:\x86_64-5.3.0-release-posix-seh-rt_v4-rev0\mingw64\bin\g++
COMPILER : C:\x86_64-5.3.0-release-posix-seh-rt_v4-rev0\mingw64\bin\g++
DEFINES : -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -m64 -DMATLAB_MEX_FILE
MATLABMEX : -DMATLAB_MEX_FILE
CFLAGS : -fexceptions -fno-omit-frame-pointer
CXXFLAGS : -fexceptions -fno-omit-frame-pointer -std=c++11
INCLUDE : -I"C:\Program Files\MATLAB\R2018a/extern/include" -I"C:\Program Files\MATLAB\R2018a/simulink/include"
CXXOPTIMFLAGS : -O -DNDEBUG
CXXDEBUGFLAGS : -g
LDXX : C:\x86_64-5.3.0-release-posix-seh-rt_v4-rev0\mingw64\bin\g++
LINKER : C:\x86_64-5.3.0-release-posix-seh-rt_v4-rev0\mingw64\bin\g++
LDFLAGS : -m64 -Wl,--no-undefined
LDTYPE : -shared -static
LINKEXPORT : -Wl,"C:\Program Files\MATLAB\R2018a/extern/lib/win64/mingw64/mexFunction.def"
LINKEXPORTVER : -Wl,"C:\Program Files\MATLAB\R2018a/extern/lib/win64/mingw64/exportsmexfileversion.def"
LIBLOC : C:\Program Files\MATLAB\R2018a\extern\lib\win64\mingw64
LINKLIBS : -L"C:\Program Files\MATLAB\R2018a\extern\lib\win64\mingw64" -llibmx -llibmex -llibmat -lm -llibmwlapack -llibmwblas -llibMatlabDataArray -llibMatlabEngine
LDOPTIMFLAGS : -s
LDDEBUGFLAGS : -g
OBJEXT : .obj
LDEXT : .mexw64
SETENV : set COMPILER=C:\x86_64-5.3.0-release-posix-seh-rt_v4-rev0\mingw64\bin\gcc
set CXXCOMPILER=C:\x86_64-5.3.0-release-posix-seh-rt_v4-rev0\mingw64\bin\g++
set COMPFLAGS=-c -fexceptions -fno-omit-frame-pointer -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -m64 -DMATLAB_MEX_FILE -DMATLAB_MEX_FILE
set CXXCOMPFLAGS=-c -fexceptions -fno-omit-frame-pointer -std=c++11 -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -m64 -DMATLAB_MEX_FILE -DMATLAB_MEX_FILE
set OPTIMFLAGS=-O -DNDEBUG
set DEBUGFLAGS=-g
set LINKER=C:\x86_64-5.3.0-release-posix-seh-rt_v4-rev0\mingw64\bin\gcc
set CXXLINKER=C:\x86_64-5.3.0-release-posix-seh-rt_v4-rev0\mingw64\bin\g++
set LINKFLAGS=-m64 -Wl,--no-undefined -shared -static -L"C:\Program Files\MATLAB\R2018a\extern\lib\win64\mingw64" -llibmx -llibmex -llibmat -lm -llibmwlapack -llibmwblas -llibMatlabDataArray -llibMatlabEngine -Wl,"C:\Program Files\MATLAB\R2018a/extern/lib/win64/mingw64/mexFunction.def"
set LINKDEBUGFLAGS=-g
set NAME_OUTPUT= -o "%OUTDIR%%MEX_NAME%%MEX_EXT%"
MINGWROOT : C:\x86_64-5.3.0-release-posix-seh-rt_v4-rev0\mingw64
MINGWTARGET : x86_64-w64-mingw32
MATLABROOT : C:\Program Files\MATLAB\R2018a
ARCH : win64
SRC : "C:\IJDAR-Binarization\imgcut3.cpp";"C:\Program Files\MATLAB\R2018a\extern\version\cpp_mexapi_version.cpp"
OBJ : C:\Users\DAVID\AppData\Local\Temp\mex_192127030071693_10192\imgcut3.obj;C:\Users\DAVID\AppData\Local\Temp\mex_192127030071693_10192\cpp_mexapi_version.obj
OBJS : C:\Users\DAVID\AppData\Local\Temp\mex_192127030071693_10192\imgcut3.obj C:\Users\DAVID\AppData\Local\Temp\mex_192127030071693_10192\cpp_mexapi_version.obj
SRCROOT : C:\IJDAR-Binarization\imgcut3
DEF : C:\Users\DAVID\AppData\Local\Temp\mex_192127030071693_10192\imgcut3.def
EXP : "imgcut3.exp"
LIB : "imgcut3.lib"
EXE : imgcut3.mexw64
ILK : "imgcut3.ilk"
MANIFEST : "imgcut3.mexw64.manifest"
TEMPNAME : imgcut3
EXEDIR :
EXENAME : imgcut3
OPTIM : -O -DNDEBUG
LINKOPTIM : -s
CMDLINE1_0 : C:\x86_64-5.3.0-release-posix-seh-rt_v4-rev0\mingw64\bin\g++ -c -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -m64 -DMATLAB_MEX_FILE -I"C:\Program Files\MATLAB\R2018a/extern/include" -I"C:\Program Files\MATLAB\R2018a/simulink/include" -fexceptions -fno-omit-frame-pointer -std=c++11 -O -DNDEBUG "C:\IJDAR-Binarization\imgcut3.cpp" -o C:\Users\DAVID\AppData\Local\Temp\mex_192127030071693_10192\imgcut3.obj
CMDLINE1_1 : C:\x86_64-5.3.0-release-posix-seh-rt_v4-rev0\mingw64\bin\g++ -c -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -m64 -DMATLAB_MEX_FILE -I"C:\Program Files\MATLAB\R2018a/extern/include" -I"C:\Program Files\MATLAB\R2018a/simulink/include" -fexceptions -fno-omit-frame-pointer -std=c++11 -O -DNDEBUG "C:\Program Files\MATLAB\R2018a\extern\version\cpp_mexapi_version.cpp" -o C:\Users\DAVID\AppData\Local\Temp\mex_192127030071693_10192\cpp_mexapi_version.obj
-------------------------------------------------------------------
Building with 'MinGW64 Compiler (C++)'.
C:\x86_64-5.3.0-release-posix-seh-rt_v4-rev0\mingw64\bin\g++ -c -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -m64 -DMATLAB_MEX_FILE -I"C:\Program Files\MATLAB\R2018a/extern/include" -I"C:\Program Files\MATLAB\R2018a/simulink/include" -fexceptions -fno-omit-frame-pointer -std=c++11 -O -DNDEBUG "C:\IJDAR-Binarization\imgcut3.cpp" -o C:\Users\DAVID\AppData\Local\Temp\mex_192127030071693_10192\imgcut3.obj
Error using mex
C:\IJDAR-Binarization\imgcut3.cpp: In function 'void mexFunction(int, mxArray**, int, const mxArray**)':
C:\IJDAR-Binarization\imgcut3.cpp:43:44: error: cannot convert 'const mwSize* {aka const long long unsigned int*}' to
'const int*' in initialization
const int *dim1 = mxGetDimensions(prhs[0]);
^
C:\IJDAR-Binarization\imgcut3.cpp:44:44: error: cannot convert 'const mwSize* {aka const long long unsigned int*}' to
'const int*' in initialization
const int *dim2 = mxGetDimensions(prhs[1]);
^
C:\IJDAR-Binarization\imgcut3.cpp:52:10: error: cannot convert 'const mwSize* {aka const long long unsigned int*}' to
'const int*' in assignment
dim2 = mxGetDimensions(prhs[2+i]);
^
C:\IJDAR-Binarization\imgcut3.cpp:106:68: error: cannot convert 'const int*' to 'const mwSize* {aka const long long
unsigned int*}' for argument '2' to 'mxArray* mxCreateNumericArray_730(mwSize, const mwSize*, mxClassID,
mxComplexity)'
plhs[0] = mxCreateNumericArray(ndim, dim1, mxDOUBLE_CLASS, mxREAL);
^
Answers (2)
Walter Roberson
on 24 Jan 2020
const int *dim1 = mxGetDimensions(prhs[0]);
mxGetDimensions does not return int*
const mwSize *mxGetDimensions(const mxArray *pm);
it returns mwSize*
Geoff Hayes
on 24 Jan 2020
const mwSize *mxGetDimensions(const mxArray *pm);
which means that your code should be
const mwSize *dim1 = mxGetDimensions(prhs[0]);
where you use mwSize instead of int. This change should also fix the error with
plhs[0] = mxCreateNumericArray(ndim, dim1, mxDOUBLE_CLASS, mxREAL);
since dim1 will now be of type mwSize.
Categories
Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!