MATLAB mexFunction() with Cygwin GCC Windows

2007-09-26 Thread Boyd Edmondson
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 mex.h
#include stdio.h

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/



Re: MATLAB mexFunction() with Cygwin GCC Windows

2007-09-26 Thread Igor Peshansky
On Wed, 26 Sep 2007, Boyd Edmondson wrote:

 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
 =
 [snip]
 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 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
^^^
See the underlined portions above.  You're not using the Cygwin gcc,
you're really using the MinGW gcc that understands Cygwin paths.  So
you're better off asking on the MinGW list.
Igor
-- 
http://cs.nyu.edu/~pechtcha/
  |\  _,,,---,,_[EMAIL PROTECTED] | [EMAIL PROTECTED]
ZZZzz /,`.-'`'-.  ;-;;,_Igor Peshansky, Ph.D. (name changed!)
 |,4-  ) )-,_. ,\ (  `'-'   old name: Igor Pechtchanski
'---''(_/--'  `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

Belief can be manipulated.  Only knowledge is dangerous.  -- Frank Herbert
--
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/

RE: MATLAB mexFunction() with Cygwin GCC Windows

2007-09-26 Thread Boyd Edmondson
Done.  Thanks.

Boyd
-Original Message-
From: Igor Peshansky [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, September 26, 2007 7:24 AM
To: Boyd Edmondson
Cc: cygwin@cygwin.com
Subject: Re: MATLAB mexFunction() with Cygwin GCC Windows

On Wed, 26 Sep 2007, Boyd Edmondson wrote:

 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
 =
 [snip]
 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 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
^^^
See the underlined portions above.  You're not using the Cygwin gcc,
you're really using the MinGW gcc that understands Cygwin paths.  So
you're better off asking on the MinGW list.
Igor
-- 
http://cs.nyu.edu/~pechtcha/
  |\  _,,,---,,_[EMAIL PROTECTED] | [EMAIL PROTECTED]
ZZZzz /,`.-'`'-.  ;-;;,_Igor Peshansky, Ph.D. (name changed!)
 |,4-  ) )-,_. ,\ (  `'-'   old name: Igor Pechtchanski
'---''(_/--'  `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

Belief can be manipulated.  Only knowledge is dangerous.  -- Frank Herbert

--
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/