MATLAB: Can’t I mex cpp with matlab

macmexxcode

I am running Matlab 2016a on Mac OS X El Capitan 10.11.6. And I have Xcode 6.4. When I input 'mex -setup' in Matlab, it goes well as followed
>> mex -setup
MEX configured to use 'Xcode with Clang' for C language compilation.
Warning: The MATLAB C and Fortran API has changed to support MATLAB
variables with more than 2^32-1 elements. In the near future
you will be required to update your code to utilize the
new API. You can find more information about this at:
http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.
To choose a different language, select one from the following:
mex -setup C++
mex -setup FORTRAN
But when I mex a cpp on my matlab, I got an error message like this:
>> GCO_UnitTest
Building with 'Xcode Clang++'.
Error using mex
In file included from /Users/Downloads/decolor/gco-v3.0/matlab/gco_matlab.cpp:5:
In file included from
/Users/Downloads/decolor/gco-v3.0/matlab/../GCoptimization.h:109:
/Users/Downloads/decolor/gco-v3.0/matlab/../energy.h:262:2: warning: 'register'
storage class specifier is deprecated [-Wdeprecated-register]
register Value pi = (E000 + E011 + E101 + E110) - (E100 + E010 + E001 + E111);
^~~~~~~~~
/Users/Downloads/decolor/gco-v3.0/matlab/../energy.h:263:2: warning: 'register'
storage class specifier is deprecated [-Wdeprecated-register]
register Value delta;
^~~~~~~~~
/Users/Downloads/decolor/gco-v3.0/matlab/../energy.h:264:2: warning: 'register'
storage class specifier is deprecated [-Wdeprecated-register]
register Var u;
^~~~~~~~~
In file included from /Users/Downloads/decolor/gco-v3.0/matlab/gco_matlab.cpp:5:
In file included from
/Users/Downloads/decolor/gco-v3.0/matlab/../GCoptimization.h:111:
/Users/Downloads/decolor/gco-v3.0/matlab/../maxflow.cpp:366:16: warning: using the
result of an assignment as a condition without parentheses [-Wparentheses]
if (i->parent = a0_min)
~~~~~~~~~~^~~~~~~~
/Users/Downloads/decolor/gco-v3.0/matlab/../maxflow.cpp:366:16: note: place
parentheses around the assignment to silence this warning
if (i->parent = a0_min)
^
( )
/Users/Downloads/decolor/gco-v3.0/matlab/../maxflow.cpp:366:16: note: use '==' to
turn this assignment into an equality comparison
if (i->parent = a0_min)
^
==
/Users/Downloads/decolor/gco-v3.0/matlab/../maxflow.cpp:443:16: warning: using the
result of an assignment as a condition without parentheses [-Wparentheses]
if (i->parent = a0_min)
~~~~~~~~~~^~~~~~~~
/Users/Downloads/decolor/gco-v3.0/matlab/../maxflow.cpp:443:16: note: place
parentheses around the assignment to silence this warning
if (i->parent = a0_min)
^
( )
/Users/Downloads/decolor/gco-v3.0/matlab/../maxflow.cpp:443:16: note: use '==' to
turn this assignment into an equality comparison
if (i->parent = a0_min)
^
==
/Users/Downloads/decolor/gco-v3.0/matlab/gco_matlab.cpp:8:13: error: typedef
redefinition with different types ('int' vs 'size_t' (aka 'unsigned long'))
typedef int mwSize;
^
/Applications/MATLAB_R2016a.app/extern/include/tmwtypes.h:795:19: note: previous definition
is here
typedef size_t mwSize; /* unsigned pointer-width integer */
^
/Users/Downloads/decolor/gco-v3.0/matlab/gco_matlab.cpp:9:13: error: typedef
redefinition with different types ('int' vs 'size_t' (aka 'unsigned long'))
typedef int mwIndex;
^
/Applications/MATLAB_R2016a.app/extern/include/tmwtypes.h:796:19: note: previous definition
is here
typedef size_t mwIndex; /* unsigned pointer-width integer */
^
5 warnings and 2 errors generated.
Error in GCO_BuildLib (line 77)
eval(mexcmd); % compile and link in one step
Error in GCO_UnitTest (line 48)
GCO_BuildLib; disp('BuildLib PASSED');
I am confused on this problem for several days and have tried some solutions but no fixed. Could someone help me with this? Thanks!

Best Answer

The code you are compiling is outdated.
/Users/Downloads/decolor/gco-v3.0/matlab/gco_matlab.cpp lines 8 and 9 use
typedef int mwSize;
typedef int mwIndex;
There was a time when mwSize and mwIndex were "int", but that was a number of years ago, when only 32 bit systems were supported. They were changed to size_t . You should either remove those two lines or change the int to size_t