Delivered-To: listarch-cygwin AT sourceware DOT cygnus DOT com Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm Sender: cygwin-owner AT sourceware DOT cygnus DOT com Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com Content-return: allowed Date: Tue, 09 Feb 1999 19:44:03 -0800 From: "Vasudevan, Gopal" Subject: Help on mexing with Mingw32 and g77! To: "'cygwin AT sourceware DOT cygnus DOT com'" Message-id: <7B07215DF838D211A4440000F81F0665161E1F@emss01m09.ems.lmco.com> MIME-version: 1.0 X-Mailer: Internet Mail Service (5.5.2232.9) Content-type: text/plain; charset="iso-8859-1" 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 DOT vasudevan AT lmco DOT 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 AT 8 mexgetmatrixptr_=MEXGETMATRIXPTR AT 8 mexputmatrix_=MEXPUTMATRIX AT 4 mxfreematrix_=MXFREEMATRIX AT 4 mxisnumeric_=MXISNUMERIC AT 4 mxsetname1_=MXSETNAME AT 12 mxsetnzmax_=MXSETNZMAX AT 8 mexcallmatlab_=MEXCALLMATLAB AT 24 mexerrmsgtxt_=MEXERRMSGTXT AT 8 mexevalstring_=MEXEVALSTRING AT 8 mexgeteps_=MEXGETEPS AT 0 mexgetfull_=MEXGETFULL AT 24 mexgetglobal_=MEXGETGLOBAL AT 8 mexgetinf_=MEXGETINF AT 0 mexgetnan_=MEXGETNAN AT 0 mexisfinite_=MEXISFINITE AT 4 mexisinf_=MEXISINF AT 4 mexisnan_=MEXISNAN AT 4 mexprintf_=MEXPRINTF AT 8 mexputfull_=MEXPUTFULL AT 24 mexsettrapflag_=MEXSETTRAPFLAG AT 4 mexatexit_=MEXATEXIT AT 4 mxcalloc_=MXCALLOC AT 8 mxcreatefull_=MXCREATEFULL AT 12 mxcreatesparse16_=MXCREATESPARSE AT 16 mxcreatestring_=MXCREATESTRING AT 8 mxfree_=MXFREE AT 4 mxgetir_=MXGETIR AT 4 mxgetjc_=MXGETJC AT 4 mxgetm_=MXGETM AT 4 mxgetn_=MXGETN AT 4 mxgetname1_=MXGETNAME AT 12 mxgetnzmax_=MXGETNZMAX AT 4 mxgetpi_=MXGETPI AT 4 mxgetpr_=MXGETPR AT 4 mxgetscalar_=MXGETSCALAR AT 4 mxgetstring16_=MXGETSTRING AT 16 mxiscomplex_=MXISCOMPLEX AT 4 mxisdouble_=MXISDOUBLE AT 4 mxisfull_=MXISFULL AT 4 mxissparse_=MXISSPARSE AT 4 mxisstring_=MXISSTRING AT 4 mxsetir_=MXSETIR AT 8 mxsetjc_=MXSETJC AT 8 mxsetm_=MXSETM AT 8 mxsetn_=MXSETN AT 8 mxsetpi_=MXSETPI AT 8 mxsetpr_=MXSETPR AT 8 mxsetstring_=MXSETSTRING AT 4 mxcopycharactertoptr_=MXCOPYCHARACTERTOPTR AT 16 mxcopyptrtocharacter_=MXCOPYPTRTOCHARACTER AT 16 mxcopycomplex16toptr_=MXCOPYCOMPLEX16TOPTR AT 16 mxcopyptrtocomplex16_=MXCOPYPTRTOCOMPLEX16 AT 16 mxcopyinteger4toptr_=MXCOPYINTEGER4TOPTR AT 12 mxcopyptrtointeger4_=MXCOPYPTRTOINTEGER4 AT 12 mxcopyreal8toptr_=MXCOPYREAL8TOPTR AT 12 mxcopyptrtoreal8_=MXCOPYPTRTOREAL8 AT 12 mxcopyptrtoptrarray_=MXCOPYPTRTOPTRARRAY AT 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 AT sourceware DOT cygnus DOT com