MATLAB Answers

Translated by

このページのコンテンツは英語から自動翻訳されています。自動翻訳をオフにする場合は「<a class="turn_off_mt" href="#">ここ</a>」をクリックしてください。


mxCreateNumericArray error: cannot convert 'int*' to 'const size_t* {aka const long long unsigned int*}' for argument '2' to 'mxArray*

Dick Oosthuizen さんによって質問されました 2019 年 5 月 16 日
最新アクティビティ Dick Oosthuizen さんによって コメントされました 2019 年 5 月 17 日 22:52
I am trying to replicate the paper of Druedahl and Jorgensen (2017), with title "A general endogenous grid method for multi-dimensional models with non-convexities and constraints". However, I have an issue with the compiler in matlab, to read C++ files. More specifically, when I do in matlab:
mex cfuncs\mexUpperEnvelopeToCommon.cpp CXXFLAGS="$CXXFLAGS -fopenmp -std=c++11 -O3 -march=native -ffast-math -fabi-version=0 -mavx2" C:\TDM-GCC-64\lib\gcc\x86_64-w64-mingw32\5.1.0\libgomp.a;
I get the error:
error: cannot convert 'int*' to 'const
size_t* {aka const long long unsigned int*}' for argument '2' to 'mxArray* mxCreateNumericArray_730(size_t, const
size_t*, mxClassID, mxComplexity)'
plhs[iout] = mxCreateNumericArray(par->ndim,dims,mxLOGICAL_CLASS,mxREAL);
Also mex -DMX_COMPAT_32 cfuncs\mexUpperEnvelopeToCommon.cpp gives the same error.
I already tried to replace all int with mwSize. However, there are also two int* in the file, and I do not know how to replace those.
Does anyone know how to solve the issue? I attach the zip file with the C++ functions.

  0 件のコメント

サインイン to comment.

1 件の回答

回答者: James Tursa
2019 年 5 月 16 日
編集済み: James Tursa
2019 年 5 月 16 日

Simply replace this
int* dims = new int[par->ndim];
with this
mwSize* dims = new mwSize[par->ndim];

  6 件のコメント

Please show the complete mex command you are using and the resulting error. I clearly see mexFunction in your mexUpperEnvelopeToCommon.cpp file, so I don't understand the error yet.
I run:
mex cfuncs\mexUpperEnvelopeToCommon.cpp XXFLAGS="$CXXFLAGS -fopenmp -std=c++11 -O3 -march=native -ffast-math -fabi-version=0 -mavx2" C:\TDM-GCC-64\lib\gcc\x86_64-w64-mingw32\5.1.0\libgomp.a;
I get:
Building with 'MinGW64 Compiler (C++)'.
Error using mex
Cannot export mexFunction: symbol not defined
collect2.exe: error: ld returned 1 exit status
I found my error! It had to do with the MexFunction. Thank you so much!

サインイン to comment.

Translated by