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

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.

 採用された回答

James Tursa
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];

7 件のコメント

Dick Oosthuizen
Dick Oosthuizen 2019 年 5 月 16 日
Then I get the following error:
cfuncs\mexUpperEnvelopeToCommon.cpp:223:77: error: cannot convert 'mwSize* {aka long
long unsigned int*}' to 'int*' for argument '3' to 'void mesh::create(mesh::settings_struct*, int, int*, double**,
double*)'
mesh::create(w_interp_func, par->ndim, grid_lengths, grid_vectors, w);
James Tursa
James Tursa 2019 年 5 月 17 日
So, how did changing the dims definition affect grid_lengths? Did you incorrectly change grid_lengths to mwSize* when you should have left it as int*?
Dick Oosthuizen
Dick Oosthuizen 2019 年 5 月 17 日
I fixed that, then i get the error:
Error using mex
Cannot export mexFunction: symbol not defined
collect2.exe: error: ld returned 1 exit status
James Tursa
James Tursa 2019 年 5 月 17 日
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.
Dick Oosthuizen
Dick Oosthuizen 2019 年 5 月 17 日
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
Dick Oosthuizen
Dick Oosthuizen 2019 年 5 月 17 日
I found my error! It had to do with the MexFunction. Thank you so much!
晓航 邵
晓航 邵 2022 年 5 月 18 日
Do you finally use this kinof commamd "mex -compatibleArrayDims readTrackletsMex.cpp".
But why it does work in my situation? Could you tell me how to solve it?
errors still occurred like:
使用 'g++' 编译。
错误使用 mex
/home/shawn/Documents/MATLAB/StereoKittiSLAM/utilsRawData/readTrackletsMex.cpp: In function ‘void mexFunction(int, mxArray**, int, const
mxArray**)’:
/home/shawn/Documents/MATLAB/StereoKittiSLAM/utilsRawData/readTrackletsMex.cpp:76:82: warning: narrowing conversion of
‘tracklets->Tracklets::getTracklet(tracklet_idx)->Tracklets::tTracklet::poses.std::vector<Tracklets::tPose>::size()’ from
‘std::vector<Tracklets::tPose>::size_type {aka long unsigned int}’ to ‘int’ inside { } [-Wnarrowing]
const int poses_dim[] = {15, tracklets->getTracklet(tracklet_idx)->poses.size()};
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
/home/shawn/Documents/MATLAB/StereoKittiSLAM/utilsRawData/readTrackletsMex.cpp:108:3: error: ‘cout’ was not declared in this scope
cout << "Found " << tracklets->numberOfTracklets() << " tracklets." << endl;
^~~~

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB Compiler についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by