我对MATLAB有点陌生,但目前正在尝试使用G ++(版本6.3)作为编译器来构建MEX文件。我收到此错误
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
我不明白。为什么/usr/local/MATLAB/R2016a/extern/include/tmwtypes.h
的{{1}}定义与mwSize
冲突?它们不是MATLAB随附的预定义库(这意味着它们应该可以正常工作吗?)
顺便说一下,/usr/local/MATLAB/R2016a/extern/include/mex.h
的一行包含上述/disks/local/sceneflow2/./external/libtrws/trwsMex.cpp
。
答案 0 :(得分:2)
错误消息必须阻止(针对两个不同的错误),让我们仅看第一个。我将其分为三个“行”:
/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’
第一行说,编译器在mwSize
文件的第14行找到了trwsMex.cpp
的声明,并在其中声明了typedef int mwSize
。
最后一行说此mwSize
已在MATLAB随附的tmwtypes.h
标头中定义。
第二行说此头文件由matrix.h
包含,由mex.h
包含,而trwsMex.cpp
包含在第9行。
因此,要解决该错误,请不要在MEX文件源代码中定义mwSize
和mwIndex
,这些是由MATLAB的标头定义的。