This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project. See the Cygwin home page for more information.
[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index] [Subject Index] [Author Index] [Thread Index]

Help on mexing with Mingw32 and g77!



Hi,
I do not know if this is the right forum to bring this up, but, I have been
struggling to mex some files on on a windows95 platform.  I am using egcs
ver 1.1.1 using Mingw32. With some amount of struggling I did manage to
compile and create a  .dll file only to have Matlab 5.2 complain:
             ??? DLL load failed for mex file , error is A device attached
to the system is not functioning.

Here is my procedure to create the aforementioned .dll file.   I am using
the example files fprime.f and fprimeG.f.
I have been successful in mexing the equivalent .c function to a working
.dll.   Any ideas?   I have looked through almost every web site that talked
about even remotely about mex.

I would dearly appreciate any pointers.    Please email me at
gopal.vasudevan@lmco.com

Makefile:
CXX = c++
FC = g77

DEBUG=-g
ARCH=-march=i586
MATLAB=c:/matlab
DEF_DIR=$(MATLAB)/extern/include

DLLTOOL=dlltool
DLLWRAP=dllwrap
CFLAGS= $(DEBUG) -mwindows $(ARCH) -Wall
CXXFLAGS = $(DEBUG)
CFLAGS = $(DEBUG)
FFLAGS = $(DEBUG) -Wall -O -fno-backslash -ff90
CPPFLAGS = -I.

INCLUDES = -Ic:/matlab/extern/include -Ic:/matlab/simulink/include

SOURCES = fprimeG.f fprime.f
DLL_NAME = fprime.dll
OBJECTS := $(SOURCES:.c=.o)
OBJECTS := $(OBJECTS:.f=.o)

DLL_CFLAGS=-DBUILDING_DLL=1
DLL_FFLAGS=

# matlab libraries that your DLL depends on.
#DLL_LDLIBS = matlab.a
DLL_EXP_DEF=$(DEF_DIR)/g77mex.def
DLL_LDLIBS=flib.a

all: $(DLL_NAME) clean
###
#
# Making DLL
#
###
# ********************************************************************
# Library creation command
# ********************************************************************
DLLWRAP_FLAGS =  --driver-name $(FC)

$(DLL_NAME): $(OBJECTS) $(DLL_EXP_DEF) $(DLL_LDLIBS) mexversion.res
	$(DLLWRAP) $(DLLWRAP_FLAGS) -o $(DLL_NAME) $(OBJECTS) mexversion.res
$(DLL_LDFLAGS) $(DLL_LDLIBS)

$(DLL_LDLIBS):
	dlltool --export-all --def $(DEF_DIR)/g77mex_.def --output-lib
$(DLL_LDLIBS)


mexversion.res:
	windres -O coff -o mexversion.res $(DEF_DIR)/mexversion.rc

#
# default rules for building DLL objects. Note that client programs (ie.,
# the ones that *use* the DLL) have to be compiled without the DLL_CFLAGS
# flags.
#
.cc.o:
	$(CXX) -c $(DLL_CFLAGS) $(CPPFLAGS) $(CXXFLAGS) -o $@ $<
.c.o:
	$(CC) -c $(DLL_CFLAGS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) -o $@ $<
.F.o:
	$(FC) -c $(DLL_FFLAGS) $(FFLAGS) $(CPPFLAGS) -o $@ $<
.f.o:
	$(FC) -c $(DLL_FFLAGS) $(FFLAGS) -o $@ $<


clean:
	-rm -f $(OBJECTS) $(DLL_LDLIBS)

#**********End of Makefile


g77mex_.def:

EXPORTS
mexgetmatrix_=MEXGETMATRIX@8
mexgetmatrixptr_=MEXGETMATRIXPTR@8
mexputmatrix_=MEXPUTMATRIX@4
mxfreematrix_=MXFREEMATRIX@4
mxisnumeric_=MXISNUMERIC@4
mxsetname1_=MXSETNAME@12
mxsetnzmax_=MXSETNZMAX@8
mexcallmatlab_=MEXCALLMATLAB@24
mexerrmsgtxt_=MEXERRMSGTXT@8
mexevalstring_=MEXEVALSTRING@8
mexgeteps_=MEXGETEPS@0
mexgetfull_=MEXGETFULL@24
mexgetglobal_=MEXGETGLOBAL@8
mexgetinf_=MEXGETINF@0
mexgetnan_=MEXGETNAN@0
mexisfinite_=MEXISFINITE@4
mexisinf_=MEXISINF@4
mexisnan_=MEXISNAN@4
mexprintf_=MEXPRINTF@8
mexputfull_=MEXPUTFULL@24
mexsettrapflag_=MEXSETTRAPFLAG@4
mexatexit_=MEXATEXIT@4
mxcalloc_=MXCALLOC@8
mxcreatefull_=MXCREATEFULL@12
mxcreatesparse16_=MXCREATESPARSE@16
mxcreatestring_=MXCREATESTRING@8
mxfree_=MXFREE@4
mxgetir_=MXGETIR@4
mxgetjc_=MXGETJC@4
mxgetm_=MXGETM@4
mxgetn_=MXGETN@4
mxgetname1_=MXGETNAME@12
mxgetnzmax_=MXGETNZMAX@4
mxgetpi_=MXGETPI@4
mxgetpr_=MXGETPR@4
mxgetscalar_=MXGETSCALAR@4
mxgetstring16_=MXGETSTRING@16
mxiscomplex_=MXISCOMPLEX@4
mxisdouble_=MXISDOUBLE@4
mxisfull_=MXISFULL@4
mxissparse_=MXISSPARSE@4
mxisstring_=MXISSTRING@4
mxsetir_=MXSETIR@8
mxsetjc_=MXSETJC@8
mxsetm_=MXSETM@8
mxsetn_=MXSETN@8
mxsetpi_=MXSETPI@8
mxsetpr_=MXSETPR@8
mxsetstring_=MXSETSTRING@4
mxcopycharactertoptr_=MXCOPYCHARACTERTOPTR@16
mxcopyptrtocharacter_=MXCOPYPTRTOCHARACTER@16
mxcopycomplex16toptr_=MXCOPYCOMPLEX16TOPTR@16
mxcopyptrtocomplex16_=MXCOPYPTRTOCOMPLEX16@16
mxcopyinteger4toptr_=MXCOPYINTEGER4TOPTR@12
mxcopyptrtointeger4_=MXCOPYPTRTOINTEGER4@12
mxcopyreal8toptr_=MXCOPYREAL8TOPTR@12
mxcopyptrtoreal8_=MXCOPYPTRTOREAL8@12
mxcopyptrtoptrarray_=MXCOPYPTRTOPTRARRAY@12

********************* end of g77mex_.def ****************************

g77mex.def:

EXPORTS
mexfunction_

********************* end of g77mex.def ****************************

fprime.f:
C The actual YPRIME subroutine in FORTRAN
C
C Copyright (c) 1984-1998 by The MathWorks, Inc.
C All Rights Reserved.
C $Revision: 1.2 $
C

      SUBROUTINE YPRIME(YP, T, Y)
      REAL*8 YP(4), T, Y(4)

      REAL*8 MU, MUS, R1, R2
      
      MU = 1.0/82.45
      MUS = 1.0 - MU

      R1 = SQRT((Y(1)+MU)**2 + Y(3)**2)
      R2 = SQRT((Y(1)-MUS)**2 + Y(3)**2)

      YP(1) = Y(2)
      YP(2) = 2*Y(4) + Y(1) - MUS*(Y(1)+MU)/(R1**3) - 
     & MU*(Y(1)-MUS)/(R2**3)

      YP(3) = Y(4)
      YP(4) = -2*Y(2) + Y(3) - MUS*Y(3)/(R1**3) - 
     & MU*Y(3)/(R2**3)

      RETURN
      END
**************************** end of fprime.f *************************

fprimeG.f:

C YPRIMEG.FOR - Gateway function for YPRIME.FOR
C
C This is an example of the FORTRAN code required for interfacing
C a .MEX file to MATLAB.
C
C This subroutine is the main gateway to MATLAB.  When a MEX function
C  is executed MATLAB calls the MEXFUNCTION subroutine in the corresponding
C  MEX file.  
C
C Copyright (c) 1984-1998 by The MathWorks, Inc.
C All Rights Reserved.
C $Revision: 1.5 $
C
      SUBROUTINE MEXFUNCTION(NLHS, PLHS, NRHS, PRHS)

C-----------------------------------------------------------------------
C     (integer) Replace integer by integer*8 on the DEC Alpha and the
C     SGI 64-bit platforms
C
      INTEGER PLHS(*), PRHS(*)

C-----------------------------------------------------------------------
C

      INTEGER NLHS, NRHS
C
C-----------------------------------------------------------------------
C     (integer) Replace integer by integer*8 on the DEC Alpha and the
C     SGI 64-bit platforms
C
      INTEGER MXCREATEFULL, MXGETPR

C-----------------------------------------------------------------------
C

      INTEGER MXGETM, MXGETN
C
C KEEP THE ABOVE SUBROUTINE, ARGUMENT, AND FUNCTION DECLARATIONS FOR USE
C IN ALL YOUR FORTRAN MEX FILES.
C---------------------------------------------------------------------
C
C-----------------------------------------------------------------------
C     (integer) Replace integer by integer*8 on the DEC Alpha and the
C     SGI 64-bit platforms
C
      INTEGER YPP, TP, YP

C-----------------------------------------------------------------------
C

      INTEGER M, N
      REAL*8 RYPP(4), RTP, RYP(4)

C
C CHECK FOR PROPER NUMBER OF ARGUMENTS
C
      IF (NRHS .NE. 2) THEN
        CALL MEXERRMSGTXT('YPRIME requires two input arguments')
      ELSEIF (NLHS .GT. 1) THEN
        CALL MEXERRMSGTXT('YPRIME requires one output argument')
      ENDIF
C
C CHECK THE DIMENSIONS OF Y.  IT CAN BE 4 X 1 OR 1 X 4.
C
      M = MXGETM(PRHS(2))
      N = MXGETN(PRHS(2))
C
      IF ((MAX(M,N) .NE. 4) .OR. (MIN(M,N) .NE. 1)) THEN
        CALL MEXERRMSGTXT('YPRIME requires that Y be a 4 x 1 vector')
      ENDIF
C
C CREATE A MATRIX FOR RETURN ARGUMENT
C
      PLHS(1) = MXCREATEFULL(M,N,0)
C
C ASSIGN POINTERS TO THE VARIOUS PARAMETERS
C
      YPP = MXGETPR(PLHS(1))
C
      TP = MXGETPR(PRHS(1))
      YP = MXGETPR(PRHS(2))
C
C COPY RIGHT HAND ARGUMENTS TO LOCAL ARRAYS OR VARIABLES
      CALL MXCOPYPTRTOREAL8(TP, RTP, 1)
      CALL MXCOPYPTRTOREAL8(YP, RYP, 4)
C
C DO THE ACTUAL COMPUTATIONS IN A SUBROUTINE
C       CREATED ARRAYS.  
C
      CALL YPRIME(RYPP,RTP,RYP)
C
C COPY OUTPUT WHICH IS STORED IN LOCAL ARRAY TO MATRIX OUTPUT
      CALL MXCOPYREAL8TOPTR(RYPP, YPP, 4)
C
      RETURN
      END
**************************** end of fprimeG.f
********************************

Thanks
Gopal

--   
Want to unsubscribe from this list?                             
Send a message to cygwin-unsubscribe@sourceware.cygnus.com