title: Matlab 2011b and mingw64
body: <p>I've followed the guidance I found <a href="https://stackoverflow.com/questions/8552580/using-gccmingw-as-matlabs-mex-compiler">here</a>.</p>
  
  <p>I have almost completed the work. The following section is the paragraph of batch conversion work. I have created a batch file to convert a lot of DLLs pre-built by MSVC in Matlab 2011b Windows 7(64-bit).</p>
  
  <pre><code>    set path=C:\MinGW64\bin;C:\mingw\msys\bin;
  
      mkdir lib
      mkdir bin
      @echo y |copy *.dll  .\bin
      @echo y |copy *.lib  .\lib
  
      @echo EXPORTS &gt;libmex.def
      @echo EXPORTS &gt;libmx.def
      @echo EXPORTS &gt;libmat.def
      @echo EXPORTS &gt;libeng.def
      @echo EXPORTS &gt;libmwlapack.def
  
  
      c:\mingw64\bin\pexports ./bin/libmex.dll | sed "s/^_//" &gt; libmex.def
      c:\mingw64\bin\pexports ./bin/libmat.dll | sed "s/^_//" &gt; libmat.def
      c:\mingw64\bin\pexports ./bin/libeng.dll | sed "s/^_//" &gt; libeng.def
      c:\mingw64\bin\pexports ./bin/libmwlapack.dll | sed "s/^_//" &gt;libmwlapack.def
      gendef ./bin/libmx.dll
  
      echo "Add the mexErrMsgTxt string to each def file,"
      echo "then press any key to continue the conversion process"
      pause
  
      lib /machine:x64 /def:libmex.def /name:.\bin\libmex.dll /out:.\lib\libmex.lib
      lib /machine:x64 /def:libmx.def  /name:.\bin\libmx.dll  /out:.\lib\libmx.lib
      lib /machine:x64 /def:libmat.def /name:.\bin\libmat.dll /out:.\lib\libmat.lib
      lib /machine:x64 /def:libeng.def /name:.\bin\libeng.dll /out:.\lib\libeng.lib
      lib /machine:x64 /def:libmwlapack.def /name:.\bin\libmwlapack.dll /out:.\lib\libmwlapack.lib
  
      c:\mingw64\bin\x86_64-w64-mingw32-dlltool --kill-at -U -d libmex.def -l /lib/libmex.a
      c:\mingw64\bin\x86_64-w64-mingw32-dlltool --kill-at -U -d libmat.def -l ./lib/libmat.a
      c:\mingw64\bin\x86_64-w64-mingw32-dlltool --kill-at -U -d libeng.def -l ./lib/libeng.a
      c:\mingw64\bin\x86_64-w64-mingw32-dlltool --kill-at -U -d libmx.def -l./lib/libmx.a
      c:\mingw64\bin\x86_64-w64-mingw32-dlltool --kill-at -U -d libmwlapack.def -l ./lib/libmwlapack.a
  </code></pre>
  
  <p>Makefile for engwindemo.exe:</p>
  
  <pre><code>    LIBS= -Lc:/mingw64/lib ../lib/libeng.a ../lib/libmx.a ../lib/
      libmex.a ../lib/libmat.a
  
      CC=c:/mingw64/bin/gcc -m64 -O3 -I../include -Ic:/mingw64/include
  
      EXE=../bin/engwindemo.exe
  
      SRC=engwindemo.c
  
      all:$(EXE)
  
      $(EXE):  $(SRC)
             $(CC) $(SRC) $(LIBS) -L../lib -ladvapi32 -luser32 -lgdi32 -lkernel32 -
      lmingwex -o $(EXE)
             @rm -f *.o*
  </code></pre>
  
  <p>Using (mingw64) gcc, the compiling and linking processes is ok. Execute engwindemo.exe, I get this error:</p>
  
  <blockquote>
    <p>_engClose entry point error (in libeng.dll)</p>
  </blockquote>
  
  <p>In mingw64, how can I build a stand-alone application (engwindemo.exe) which calls from the functions built-in the libeng.dll (Matlab R2011b)?</p>