在 MATLAB 上使用 G++ 构建问题
Problems building with G++ on MATLAB
我对 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
对 mwSize
的定义与 /usr/local/MATLAB/R2016a/extern/include/mex.h
冲突?它们不是包含在 MATLAB 中的预定义库吗(意味着它们应该可以正常工作?)
顺便说一下,/disks/local/sceneflow2/./external/libtrws/trwsMex.cpp
有一行包含上述 mex.h
。
错误消息必须阻塞(对于两个不同的错误),让我们只看第一个。我把它分成三个 "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’
第一行表示编译器在 trwsMex.cpp
文件的第 14 行找到了 mwSize
的声明,其中显示 typedef int mwSize
.
最后一行说这个mwSize
已经在MATLAB自带的tmwtypes.h
header中定义了
第二行说这个 header 文件被 matrix.h
包含,它被 mex.h
包含,它被你在第 9 行的 trwsMex.cpp
包含。
因此,要修复错误,请不要在 MEX-file 源代码中定义 mwSize
和 mwIndex
,它们由 MATLAB 的 header 定义。
我对 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
对 mwSize
的定义与 /usr/local/MATLAB/R2016a/extern/include/mex.h
冲突?它们不是包含在 MATLAB 中的预定义库吗(意味着它们应该可以正常工作?)
顺便说一下,/disks/local/sceneflow2/./external/libtrws/trwsMex.cpp
有一行包含上述 mex.h
。
错误消息必须阻塞(对于两个不同的错误),让我们只看第一个。我把它分成三个 "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’
第一行表示编译器在 trwsMex.cpp
文件的第 14 行找到了 mwSize
的声明,其中显示 typedef int mwSize
.
最后一行说这个mwSize
已经在MATLAB自带的tmwtypes.h
header中定义了
第二行说这个 header 文件被 matrix.h
包含,它被 mex.h
包含,它被你在第 9 行的 trwsMex.cpp
包含。
因此,要修复错误,请不要在 MEX-file 源代码中定义 mwSize
和 mwIndex
,它们由 MATLAB 的 header 定义。