在matlab中使用mex编译失败

时间:2018-05-09 18:50:05

标签: c++ matlab mex

我正在尝试使用mex编译c代码。为此,我按照此链接(mathworks.com/help/matlab/ref/mex.html)中描述的两行命令运行。

copyfile(fullfile(matlabroot,'extern','examples','mex','yprime.c'),'.','f')
mex yprime.c

但是,由于以下错误导致编译失败(参见附件截图) enter image description here

注意:我有matlab R2018a版本。此外,在编译之前,我通过matlab的Add-On按钮安装了MinGW-w64。我检查了gcc在路径中是否可用,我编译了另一个c代码(通过Windows命令行),以确保它编译没有问题。通过命令行编译时没有问题,但在matlab中使用mex进行编译失败。

如果你能告诉我如何解决这个问题,我将不胜感激。 我也试过

mex -v yprime.c

这是调试输出

 Verbose mode is on.
... Looking for compiler 'MinGW64 Compiler (C)' ...
... Looking for environment variable 'MW_MINGW64_LOC' ...Yes ('C:\ProgramData\MATLAB\SupportPackages\R2018a\3P.instrset\mingw_w64.instrset').
... Looking for file 'C:\ProgramData\MATLAB\SupportPackages\R2018a\3P.instrset\mingw_w64.instrset\bin\gcc.exe' ...Yes.
... Looking for folder 'C:\ProgramData\MATLAB\SupportPackages\R2018a\3P.instrset\mingw_w64.instrset' ...Yes.
Found installed compiler 'MinGW64 Compiler (C)'.
Set PATH = C:\ProgramData\MATLAB\SupportPackages\R2018a\3P.instrset\mingw_w64.instrset\bin;C:\Program Files\MATLAB\R2018a\extern\include\win64;C:\Program Files\MATLAB\R2018a\extern\include;C:\Program Files\MATLAB\R2018a\simulink\include;C:\Program Files\MATLAB\R2018a\lib\win64;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\iverilog\bin;C:\Program Files\iverilog\gtkwave\bin;C:\Program Files\Git\cmd;C:\Program Files\TortoiseGit\bin;C:\cygwin\opt\verilator\bin\;C:\Program Files\MATLAB\R2018a\runtime\win64;C:\Program Files\MATLAB\R2018a\bin;C:\ProgramData\MATLAB\SupportPackages\R2018a\3P.instrset\mingw_w64.instrset\bin;C:\Users\Mehdi\AppData\Local\Microsoft\WindowsApps;
Set INCLUDE = C:\ProgramData\MATLAB\SupportPackages\R2018a\3P.instrset\mingw_w64.instrset\include;;C:\ProgramData\MATLAB\SupportPackages\R2018a\3P.instrset\mingw_w64.instrset\include;;
Set LIB = C:\ProgramData\MATLAB\SupportPackages\R2018a\3P.instrset\mingw_w64.instrset\lib;;C:\ProgramData\MATLAB\SupportPackages\R2018a\3P.instrset\mingw_w64.instrset\lib;;
Set MW_TARGET_ARCH = win64;win64;
Set LIBPATH = C:\Program Files\MATLAB\R2018a\extern\lib\win64;C:\Program Files\MATLAB\R2018a\extern\lib\win64;
Options file details
-------------------------------------------------------------------
    Compiler location: C:\ProgramData\MATLAB\SupportPackages\R2018a\3P.instrset\mingw_w64.instrset
    Options file: C:\Users\Mehdi\AppData\Roaming\MathWorks\MATLAB\R2018a\mex_C_win64.xml
    CMDLINE2 : C:\ProgramData\MATLAB\SupportPackages\R2018a\3P.instrset\mingw_w64.instrset\bin\gcc -m64 -Wl,--no-undefined -shared -static -s -Wl,"C:\Program Files\MATLAB\R2018a/extern/lib/win64/mingw64/exportsmexfileversion.def" C:\Users\Mehdi\AppData\Local\Temp\mex_23913243954585_6736\yprime.obj C:\Users\Mehdi\AppData\Local\Temp\mex_23913243954585_6736\c_mexapi_version.obj   -L"C:\Program Files\MATLAB\R2018a\extern\lib\win64\mingw64" -llibmx -llibmex -llibmat -lm -llibmwlapack -llibmwblas -o yprime.mexw64
    CC : C:\ProgramData\MATLAB\SupportPackages\R2018a\3P.instrset\mingw_w64.instrset\bin\gcc
    COMPILER : C:\ProgramData\MATLAB\SupportPackages\R2018a\3P.instrset\mingw_w64.instrset\bin\gcc
    DEFINES : -DMATLAB_DEFAULT_RELEASE=R2017b  -DUSE_MEX_CMD   -m64 -DMATLAB_MEX_FILE 
    MATLABMEX : -DMATLAB_MEX_FILE 
    CFLAGS : -fexceptions -fno-omit-frame-pointer
    INCLUDE : -I"C:\Program Files\MATLAB\R2018a/extern/include" -I"C:\Program Files\MATLAB\R2018a/simulink/include" -I"C:\Program Files\MATLAB\R2018a/extern\lib\win64\mingw64"
    COPTIMFLAGS : -O -DNDEBUG
    CDEBUGFLAGS : -g
    LD : C:\ProgramData\MATLAB\SupportPackages\R2018a\3P.instrset\mingw_w64.instrset\bin\gcc
    LINKER : C:\ProgramData\MATLAB\SupportPackages\R2018a\3P.instrset\mingw_w64.instrset\bin\gcc
    LDTYPE : -shared -static
    LDFLAGS : -m64 -Wl,--no-undefined
    LINKEXPORT : -Wl,"C:\Program Files\MATLAB\R2018a/extern/lib/win64/mingw64/mexFunction.def"
    LINKEXPORTVER : -Wl,"C:\Program Files\MATLAB\R2018a/extern/lib/win64/mingw64/exportsmexfileversion.def"
    LIBLOC : C:\Program Files\MATLAB\R2018a\extern\lib\win64\mingw64
    LINKLIBS : -L"C:\Program Files\MATLAB\R2018a\extern\lib\win64\mingw64" -llibmx -llibmex -llibmat -lm -llibmwlapack -llibmwblas
    LDOPTIMFLAGS : -s
    LDDEBUGFLAGS : -g
    OBJEXT : .obj
    LDEXT : .mexw64
    SETENV : set COMPILER=C:\ProgramData\MATLAB\SupportPackages\R2018a\3P.instrset\mingw_w64.instrset\bin\gcc
                set CXXCOMPILER=C:\ProgramData\MATLAB\SupportPackages\R2018a\3P.instrset\mingw_w64.instrset\bin\g++
                set COMPFLAGS=-c -fexceptions -fno-omit-frame-pointer -DMATLAB_DEFAULT_RELEASE=R2017b  -DUSE_MEX_CMD   -m64 -DMATLAB_MEX_FILE  -DMATLAB_MEX_FILE 
                set CXXCOMPFLAGS=-c -fexceptions -fno-omit-frame-pointer -std=c++11 -DMATLAB_DEFAULT_RELEASE=R2017b  -DUSE_MEX_CMD   -m64 -DMATLAB_MEX_FILE  -DMATLAB_MEX_FILE 
                set OPTIMFLAGS=-O -DNDEBUG
                set DEBUGFLAGS=-g
                set LINKER=C:\ProgramData\MATLAB\SupportPackages\R2018a\3P.instrset\mingw_w64.instrset\bin\gcc
                set CXXLINKER=C:\ProgramData\MATLAB\SupportPackages\R2018a\3P.instrset\mingw_w64.instrset\bin\g++
                set LINKFLAGS=-m64 -Wl,--no-undefined -shared -static -L"C:\Program Files\MATLAB\R2018a\extern\lib\win64\mingw64" -llibmx -llibmex -llibmat -lm -llibmwlapack -llibmwblas -Wl,"C:\Program Files\MATLAB\R2018a/extern/lib/win64/mingw64/mexFunction.def"
                set LINKDEBUGFLAGS=-g
                set NAME_OUTPUT=-o "%OUTDIR%%MEX_NAME%%MEX_EXT%"
    MINGWROOT : C:\ProgramData\MATLAB\SupportPackages\R2018a\3P.instrset\mingw_w64.instrset
    MATLABROOT : C:\Program Files\MATLAB\R2018a
    ARCH : win64
    SRC : "C:\Users\Mehdi\Desktop\New_folder\testbench\yprime.c";"C:\Program Files\MATLAB\R2018a\extern\version\c_mexapi_version.c"
    OBJ : C:\Users\Mehdi\AppData\Local\Temp\mex_23913243954585_6736\yprime.obj;C:\Users\Mehdi\AppData\Local\Temp\mex_23913243954585_6736\c_mexapi_version.obj
    OBJS : C:\Users\Mehdi\AppData\Local\Temp\mex_23913243954585_6736\yprime.obj C:\Users\Mehdi\AppData\Local\Temp\mex_23913243954585_6736\c_mexapi_version.obj 
    SRCROOT : C:\Users\Mehdi\Desktop\New_folder\testbench\yprime
    DEF : C:\Users\Mehdi\AppData\Local\Temp\mex_23913243954585_6736\yprime.def
    EXP : "yprime.exp"
    LIB : "yprime.lib"
    EXE : yprime.mexw64
    ILK : "yprime.ilk"
    MANIFEST : "yprime.mexw64.manifest"
    TEMPNAME : yprime
    EXEDIR : 
    EXENAME : yprime
    OPTIM : -O -DNDEBUG
    LINKOPTIM : -s
    CMDLINE1_0 : C:\ProgramData\MATLAB\SupportPackages\R2018a\3P.instrset\mingw_w64.instrset\bin\gcc -c -DMATLAB_DEFAULT_RELEASE=R2017b  -DUSE_MEX_CMD   -m64 -DMATLAB_MEX_FILE  -I"C:\Program Files\MATLAB\R2018a/extern/include" -I"C:\Program Files\MATLAB\R2018a/simulink/include" -I"C:\Program Files\MATLAB\R2018a/extern\lib\win64\mingw64" -fexceptions -fno-omit-frame-pointer -O -DNDEBUG "C:\Users\Mehdi\Desktop\New_folder\testbench\yprime.c" -o C:\Users\Mehdi\AppData\Local\Temp\mex_23913243954585_6736\yprime.obj
    CMDLINE1_1 : C:\ProgramData\MATLAB\SupportPackages\R2018a\3P.instrset\mingw_w64.instrset\bin\gcc -c -DMATLAB_DEFAULT_RELEASE=R2017b  -DUSE_MEX_CMD   -m64 -DMATLAB_MEX_FILE  -I"C:\Program Files\MATLAB\R2018a/extern/include" -I"C:\Program Files\MATLAB\R2018a/simulink/include" -I"C:\Program Files\MATLAB\R2018a/extern\lib\win64\mingw64" -fexceptions -fno-omit-frame-pointer -O -DNDEBUG "C:\Program Files\MATLAB\R2018a\extern\version\c_mexapi_version.c" -o C:\Users\Mehdi\AppData\Local\Temp\mex_23913243954585_6736\c_mexapi_version.obj
-------------------------------------------------------------------
Building with 'MinGW64 Compiler (C)'.
Warning: You are using an unsupported version of MinGW Compiler. To install the supported version of MinGW compiler, see: Install
MinGW-w64 Compiler.
 For a list of currently supported compilers visit https://www.mathworks.com/support/compilers. 
> In Untitled (line 4) 
C:\ProgramData\MATLAB\SupportPackages\R2018a\3P.instrset\mingw_w64.instrset\bin\gcc -c -DMATLAB_DEFAULT_RELEASE=R2017b  -DUSE_MEX_CMD   -m64 -DMATLAB_MEX_FILE  -I"C:\Program Files\MATLAB\R2018a/extern/include" -I"C:\Program Files\MATLAB\R2018a/simulink/include" -I"C:\Program Files\MATLAB\R2018a/extern\lib\win64\mingw64" -fexceptions -fno-omit-frame-pointer -O -DNDEBUG "C:\Users\Mehdi\Desktop\New_folder\testbench\yprime.c" -o C:\Users\Mehdi\AppData\Local\Temp\mex_23913243954585_6736\yprime.obj
Error using mex
The command 'C:\ProgramData\MATLAB\SupportPackages\R2018a\3P.instrset\mingw_w64.instrset\bin\gcc' exited with a return value '5'

Error in Untitled (line 4)
mex -v yprime.c

0 个答案:

没有答案