mex error: cannot convert ‘int*’ to ‘const mwSize* {aka const long unsigned int*}’

37 views (last 30 days)
Hey,
I'm trying to compile C Code for matlab with mex. It worked fine on my Mac, but under Ubuntu 18.04.04 LTS I get the following Error/Warning;
>> compile_FastEMD
Building with 'g++'.
Warning: You are using gcc version '6.5.0'. The version of gcc is not supported. The version currently supported with MEX is
'6.3.x'. For a list of currently supported compilers see: https://www.mathworks.com/support/compilers/current_release.
> In compile_FastEMD (line 1)
Error using mex
In file included from /Path/emd_hat_gd_metric_mex.cxx:3:0:
/Path/emd_hat_compute_mex.hxx:
In function ‘void emd_hat_compute_mex_impl(int, mxArray**, int, const mxArray**, bool, mxClassID)’:
/Path/emd_hat_compute_mex.hxx:137:58:
error: cannot convert aint*t to hconst mwSize* {aka const long unsigned int*} for argument ‘2’ to ‘mxArray* mxCreateNumericArray_730(mwSize, const mwSize*, mxClassID, mxComplexity)’
out[0]= mxCreateNumericArray(1, dims, classID, mxREAL);
^
/Path/emd_hat_compute_mex.hxx:145:63:
error: cannot convert int*’ to ‘const mwSize* {aka const long unsigned int*}’ for argument ‘2’ to ‘mxArray* mxCreateNumericArray_730(mwSize, const mwSize*, mxClassID, mxComplexity)’
out[1]= mxCreateNumericArray(2, Fdims, classID, mxREAL);
^
Error in compile_FastEMD (line 1)
mex -O -DNDEBUG emd_hat_gd_metric_mex.cxx
Does this have to do with the gcc version I am using? I tried installing 6.3.x but I didn't manage to install that specific version. I only found a ppa on Launchpad for Ubuntu 16.04.
I'd be super thankful if someone could point me in the right direction, by telling me either how to install gcc 6.3.x on Ubuntu 18.04 or how to fix the code to make it work with gcc 6.5.0
This is the Source Code. (From http://ofirpele.droppages.com/ , Fast and Robust Earth Mover's Distances)
To recreate what I did you have to run compile_FastEMD.m
Cheers,
Tobi

Answers (2)

James Tursa
James Tursa on 21 Apr 2020
I haven't looked at the code, but the error messages indicate you've got some definitions in your code like this:
int dims[whatever];
int Fdims[whatever];
they need to be this
mwSize dims[whatever];
mwSize Fdims[whatever];
On previous versions where you ran this code, the mwSize happened to be an int. But on your newer system it is probably a 64-bit size_t and you get a mismatch.
  2 Comments
Chiang-Heng Chien
Chiang-Heng Chien on 12 Jun 2021
I was working on another code and similar error messages appeared. This solution solved the problem! It's very helpful.

Sign in to comment.


晓航 邵
晓航 邵 on 18 May 2022
I have come up with the same problems. Do you sove it?
Errors go as follows:
mex -c readTrackletsMex.cpp
使用 '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:35:48: error: cannot convert ‘int*’ to ‘const mwSize* {aka
const long unsigned int*}’ for argument ‘2’ to ‘mxArray* mxCreateCellArray_730(mwSize, const mwSize*)’
cell_array_ptr = mxCreateCellArray(ndim, dims);
^
/home/shawn/Documents/MATLAB/StereoKittiSLAM/utilsRawData/readTrackletsMex.cpp:49:89: error: cannot convert ‘int*’ to ‘const mwSize* {aka
const long unsigned int*}’ for argument ‘2’ to ‘mxArray* mxCreateStructArray_730(mwSize, const mwSize*, int, const char**)’
struct_array_ptr = mxCreateStructArray(s_ndim, s_dims, number_of_fields, field_names);
^
/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:77:74: error: cannot convert ‘const int*’ to ‘const mwSize*
{aka const long unsigned int*}’ for argument ‘2’ to ‘mxArray* mxCreateNumericArray_730(mwSize, const mwSize*, mxClassID, mxComplexity)’
field_value = mxCreateNumericArray(2, poses_dim,mxDOUBLE_CLASS,mxREAL);
^
/home/shawn/Documents/MATLAB/StereoKittiSLAM/utilsRawData/readTrackletsMex.cpp:108:3: error: ‘cout’ was not declared in this scope
cout << "Found " << tracklets->numberOfTracklets() << " tracklets." << endl;
^~~~

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!