sabrinazuraimi
sabrinazuraimi

Reputation: 735

Problems building with G++ on MATLAB

I'm a bit new to MATLAB but am currently trying to build MEX files using G++ (version 6.3) as the compiler. I got this error

MEX completed successfully.
Building with 'g++'.
Error using mex
/disks/local/sceneflow2/./external/libtrws/trwsMex.cpp:14:13: error: conflicting declaration ‘typedef
int mwSize’
In file included from /usr/local/MATLAB/R2016a/extern/include/matrix.h:25:0,
                 from /usr/local/MATLAB/R2016a/extern/include/mex.h:51,
                 from /disks/local/sceneflow2/./external/libtrws/trwsMex.cpp:9:
/usr/local/MATLAB/R2016a/extern/include/tmwtypes.h:795:19: error: ‘mwSize’ has a previous
declaration as ‘typedef size_t mwSize’
/disks/local/sceneflow2/./external/libtrws/trwsMex.cpp:15:13: error: conflicting declaration ‘typedef
int mwIndex’
In file included from /usr/local/MATLAB/R2016a/extern/include/matrix.h:25:0,
                 from /usr/local/MATLAB/R2016a/extern/include/mex.h:51,
                 from /disks/local/sceneflow2/./external/libtrws/trwsMex.cpp:9:
/usr/local/MATLAB/R2016a/extern/include/tmwtypes.h:796:19: error: ‘mwIndex’ has a previous
declaration as ‘typedef size_t mwIndex’


Error in make_mex (line 20)
mex ./external/libtrws/trwsMex.cpp -largeArrayDims CXXFLAGS="\$CXXFLAGS -std=c++0x -fpermissive"
-outdir build

I don't get it. Why is /usr/local/MATLAB/R2016a/extern/include/tmwtypes.h definition of mwSize conflicting with /usr/local/MATLAB/R2016a/extern/include/mex.h? Aren't they predefined libraries included with MATLAB (meaning they should work fine?)

By the way, /disks/local/sceneflow2/./external/libtrws/trwsMex.cpp has a line which includes the aforementioned mex.h.

Upvotes: 0

Views: 171

Answers (1)

Cris Luengo
Cris Luengo

Reputation: 60780

The error message has to blocks (for two different errors), let's look at the first one only. I've split it out into three "lines":

/disks/local/sceneflow2/./external/libtrws/trwsMex.cpp:14:13: error: conflicting declaration
‘typedef int mwSize’

In file included from /usr/local/MATLAB/R2016a/extern/include/matrix.h:25:0,
                 from /usr/local/MATLAB/R2016a/extern/include/mex.h:51,
                 from /disks/local/sceneflow2/./external/libtrws/trwsMex.cpp:9:

/usr/local/MATLAB/R2016a/extern/include/tmwtypes.h:795:19: error: ‘mwSize’ has a previous
declaration as ‘typedef size_t mwSize’

The first line says that the compiler found a declaration for mwSize on line 14 of your trwsMex.cpp file, where it says typedef int mwSize.

The last line says that this mwSize was already defined in the tmwtypes.h header that comes with MATLAB.

The second line says that this header file was included by matrix.h, which is included by mex.h, which is included by your trwsMex.cpp on line 9.


So, to fix the error, don't define mwSize and mwIndex in your MEX-file source code, these are defined by MATLAB's headers.

Upvotes: 2

Related Questions