在 MATLAB 上使用 G++ 构建时出现问题

Problems building with G++ on MATLAB

本文关键字:问题 构建 G++ MATLAB      更新时间:2023-10-16

我对 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

错误消息必须阻止(对于两个不同的错误(,让我们只看第一个。我把它分成三行:

/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标头中定义。

第二行说这个头文件包含在 matrix.h 中,它包含在 mex.h 中,包含在第 9 行的trwsMex.cpp中。


因此,要修复此错误,请不要在 MEX 文件源代码中定义mwSizemwIndex,这些由 MATLAB 的标头定义。