X-Recipient: archive-cygwin AT delorie DOT com X-Spam-Check-By: sourceware.org Content-class: urn:content-classes:message Subject: MATLAB mexFunction() with Cygwin GCC Windows MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Date: Wed, 26 Sep 2007 07:18:58 -0700 Message-ID: <7C82AE18E63BBF46BFAC6364E1E4CA591087EE@nebulasoftware1.NebulaSoftware.com> From: "Boyd Edmondson" To: X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id l8QEHGcp010026 I have successfully built/linked MATLAB mex files on Windows using GCC in Cygwin.  Unfortunately, it has a runtime error.  It appears the error is due to mismatched calling coventions for parameter passing.  The MATLAB interpreter successfully invokes the mexFunction() in my shared library (.mexw32), but the passed parameters are "corrupted". I've tried GCC's "attribute" to set the mexFunction() to "cdecl", "stdcall", and "fastcall", but still no luck. Anyone know the solution? Details follow: MATLAB mexopts.bat ================= @echo off rem Cygwin GCC on Windows set MATLAB=%MATLAB% set COMPILER=gcc set COMPFLAGS=-mno-cygwin -D_WIN32 -shared -DMATLAB_MEX_FILE -Wall -c -msse3 -I"%ProgramFiles%\Pthreads\include" -I"%ProgramFiles%\Verasonics\Hal\Hal C\Includes" -o%MEX_NAME%.obj set OPTIMFLAGS=-O3 set DEBUGFLAGS=-g3 set LINKER=gcc set LINKFLAGS=-mno-cygwin -D_WIN32 -shared -DMATLAB_MEX_FILE -nostartfiles -L"%ProgramFiles%\Verasonics\Hal\Hal C\Shared Libraries" -lverasonicshalwindows -L"%ProgramFiles%\MATLAB\R2007a\bin\win32" -lmat -lmex -lmx set LINKOPTIMFLAGS=-s set LINKDEBUGFLAGS= set NAME_OUTPUT=-o%MEX_NAME%.mexw32 myMex.c ======== #include #include void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {     //x     printf("We are not successfully passing parameters. We will be successful when 'nlhs' is '1' and 'nrhs' is '0'. They are: %d and %d\n", nlhs, nrhs);     //x         // Return the result as a string.     plhs[0] = mxCreateString("Some text goes here");         return; } -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/