-3

I've followed the guidance I found here.

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).

    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 >libmex.def
    @echo EXPORTS >libmx.def
    @echo EXPORTS >libmat.def
    @echo EXPORTS >libeng.def
    @echo EXPORTS >libmwlapack.def


    c:\mingw64\bin\pexports ./bin/libmex.dll | sed "s/^_//" > libmex.def
    c:\mingw64\bin\pexports ./bin/libmat.dll | sed "s/^_//" > libmat.def
    c:\mingw64\bin\pexports ./bin/libeng.dll | sed "s/^_//" > libeng.def
    c:\mingw64\bin\pexports ./bin/libmwlapack.dll | sed "s/^_//" >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

Makefile for engwindemo.exe:

    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*

Using (mingw64) gcc, the compiling and linking processes is ok. Execute engwindemo.exe, I get this error:

_engClose entry point error (in libeng.dll)

In mingw64, how can I build a stand-alone application (engwindemo.exe) which calls from the functions built-in the libeng.dll (Matlab R2011b)?

Community
  • 1
  • 1
  • 1
    Please properly format your question and clarify your actual question. – Egon Feb 25 '12 at 08:54
  • > My question is how to build a stand-alone executable file calling the matlab 2011b (64-bit) engine via mingw64? At the above process, what are the problems – Richard Dualmann Feb 25 '12 at 11:18
  • Yes, I have followed the guide line as you attached, there are somethings I missed. Mingw64 can produced the stand-alone application calling from the libeng.dll. Actually, it is not running. – Richard Dualmann Feb 25 '12 at 11:33
  • I'm not sure why you're mixing `pexports` and `gendef` - `gendef` should replace `pexports`. Also, are you sure you use a version which is suited for 64-bit `DLL`s? Also, are you sure the resulting `DEF` files are valid? Also, it seems you're producing `MSVC` import libraries - what for? – user1071136 Feb 25 '12 at 20:47
  • It fails to produce the libmex.def by pexports (crashed), others are ok. I have no idea for this situation. Using dumpbin utility for extracting all information about libmx.dll, – Richard Dualmann Feb 26 '12 at 01:14
  • It fails to produce the libmex.def by pexports (crashed), others are ok. I have no idea for this situation. Using dumpbin utility for extracting all information about libmx.dll, the following messages are parts of information via dumpbin Microsoft (R) COFF/PE Dumper Version 10.00.40219.01 Copyright (C) Microsoft Corporation. All rights reserved. Dump of file libmx.dll PE signature found File Type: DLL FILE HEADER VALUES 8664 machine (x64) OPTIONAL HEADER VALUES 20B magic # (PE32+). It is a real x64's dll. Using the lib utility is for testing the ".def" file reason only. Thank your response! – Richard Dualmann Feb 26 '12 at 01:29

1 Answers1

-1

Thank everyone response! I have built up successfully! In the Matlab R2011b win32/64, just setting up in the cygwin(x86_64-w64-mingw32-gcc 4.5.2) environment without any dll file conversion. The part of primary setting is as following

  1. Set the MATLABROOT in short filename form (long filename may be ok.)

    MATLABROOT=c:/Progra~1/MATLAB/R2011b

  2. linking the primary libraries built by MSVC

    LIBS= -L$(MATLABROOT)/bin/win64 -lmex -lmx -lmwlapack -lmwblas -leng

  3. declare the gcc with the flags

    CC=x86_64-w64-mingw32-gcc

    CFLAG=-Wall -m64 -O3 -I$(MATLABROOT)/extern/include

    MEXFLAG=-m64 -shared -DMATLAB_MEX_FILE -I$(MATLABROOT)/extern/include -Wl,--export-all-symbols $(LIBS)

  4. Others additional parameters to keep compiler happy.

    And finally, in the cygwin consloe or mingw64 shell just make this project.

  • You're right! MinGW is capable of "direct-linking" to a DLL (see [here](http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/4/html/Using_ld_the_GNU_Linker/win32.html). Please do clean your answer (no need for a whole `makefile` to explain what to do, no need for advapi32, etc.). In particular, no need to `-L` the `/exterm/lib/win64/microsoft` library. – user1071136 Feb 26 '12 at 12:26