title: compiling with mex fail in matlab
body: <p>I am trying to compile a c-code using mex. For this I am running following two lines of command as described in this link(mathworks.com/help/matlab/ref/mex.html).</p>
  
  <pre><code>copyfile(fullfile(matlabroot,'extern','examples','mex','yprime.c'),'.','f')
  mex yprime.c
  </code></pre>
  
  <p>however, compilation fails due to following error (see attached screenshot)
  <a href="https://i.stack.imgur.com/fBoeh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fBoeh.png" alt="enter image description here"></a></p>
  
  <p>Note: I have matlab R2018a version. Also, Prior to compiling I installed MinGW-w64 through matlab's Add-On button. I checked that gcc is available in the path and I compiled another c-code (through windows command line) to make sure it compiles without problem. there was no problem when compiling through command line but compilation with mex in matlab fail.</p>
  
  <p>I would appreciate if you could advise me how to fix this problem.
  I also tried </p>
  
  <pre><code>mex -v yprime.c
  </code></pre>
  
  <p>and here is the debugging output</p>
  
  <pre><code> 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. 
  &gt; 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
  </code></pre>