Thread Subject: mex linux source for windows

Subject: mex linux source for windows

From: Lars Barring

Date: 27 Sep, 2007 20:40:29

Message: 1 of 5

Dear all,

We have a some Linux C-library code that has been
successfully mexed for Linux. Now we would like to
transport this this to the Windows environment.

I have very little experience in this area so all
suggestions would be welcome. I have been searching the
web and found some web pages on mingw, cygwin, and
gnumex. While these seems to be pointing in the right
direction, more direct/specific/hands-on suggestions and
experience would be most welcome.


Many thanks,
Lars

Subject: mex linux source for windows

From: Ralph Schleicher

Date: 28 Sep, 2007 20:29:20

Message: 2 of 5

"Lars Barring" <lars.barring@myworkplace.se> writes:

> We have a some Linux C-library code that has been
> successfully mexed for Linux. Now we would like to
> transport this this to the Windows environment.
>
> I have very little experience in this area so all
> suggestions would be welcome. I have been searching the
> web and found some web pages on mingw, cygwin, and
> gnumex. While these seems to be pointing in the right
> direction, more direct/specific/hands-on suggestions and
> experience would be most welcome.

Hi Lars,

if you want to create Windows MEX files using a Unix style build
environment, you have to setup a cross-compiler (either Linux:MinGW
or Cygwin:MinGW). Then compilation is as easy as

# Directory containing a copy of $MATLAB/bin, $MATLAB/extern, and
# $MATLAB/simulink/include from a Matlab Windows installation.
export MATLAB=/opt/w32/matlab-6.1
export MATLAB_ARCH=win32
export MEXEXT=dll
/configure --build=i686-pc-linux-gnu --host=i686-pc-mingw32

Useful tools can be found at

http://home.allgaeu.org/rschleic/rs/pub/m-config/
http://home.allgaeu.org/rschleic/rs/pub/mextool/

--
Ralph

5425 days of Linux experience.

Subject: mex linux source for windows

From: Chris Van Kleeck

Date: 1 Feb, 2008 17:20:19

Message: 3 of 5

Ralph Schleicher <rs+usenet@nunatak.allgaeu.org> wrote in
message <87ve9uwn33.fsf@bravo.nunatak.allgaeu.org>...
> "Lars Barring" <lars.barring@myworkplace.se> writes:
>
> > We have a some Linux C-library code that has been
> > successfully mexed for Linux. Now we would like to
> > transport this this to the Windows environment.
> >
> > I have very little experience in this area so all
> > suggestions would be welcome. I have been searching the
> > web and found some web pages on mingw, cygwin, and
> > gnumex. While these seems to be pointing in the right
> > direction, more direct/specific/hands-on suggestions and
> > experience would be most welcome.
>
> Hi Lars,
>
> if you want to create Windows MEX files using a Unix style
build
> environment, you have to setup a cross-compiler (either
Linux:MinGW
> or Cygwin:MinGW). Then compilation is as easy as
>
> # Directory containing a copy of $MATLAB/bin,
$MATLAB/extern, and
> # $MATLAB/simulink/include from a Matlab Windows installation.
> export MATLAB=/opt/w32/matlab-6.1
> export MATLAB_ARCH=win32
> export MEXEXT=dll
> /configure --build=i686-pc-linux-gnu --host=i686-pc-mingw32
>
> Useful tools can be found at
>
> http://home.allgaeu.org/rschleic/rs/pub/m-config/
> http://home.allgaeu.org/rschleic/rs/pub/mextool/
>
> --
> Ralph



Ralph,
Do you know if it is possible to use a Linux compiled mex
function as a s-function in Simulink (DOS). Or is there
another cross compiler required to do this?

Subject: mex linux source for windows

From: Thomas

Date: 7 Dec, 2010 11:25:05

Message: 4 of 5

I am running into a similar problem where I've a mexopts.bat written up in gfortran. It used to run in linux. Now, I want to convert the source code to be running in windows xp. Can you please post some hints as to how the cross-compilation is achieved.
Thanks,
Thomas

Subject: mex linux source for windows

From: Ralph Schleicher

Date: 11 Dec, 2010 13:42:35

Message: 5 of 5

"Thomas " <tclyue@gmail.com> writes:

Full name?

> I am running into a similar problem where I've a mexopts.bat written
> up in gfortran. It used to run in linux. Now, I want to convert the
> source code to be running in windows xp. Can you please post some
> hints as to how the cross-compilation is achieved. Thanks, Thomas

You have to setup a cross-compilation environment, that is

 * Build and install a MinGW cross-compiler toolchain on your Unix box

   Binutils: ./configure --host=i686-pc-mingw32 --target=i686-pc-mingw32
   GCC: ./configure --host=i686-pc-mingw32 --target=i686-pc-mingw32 --enable-languages=c,c++,f77

 * Install mingw-runtime and w32api in /usr/local/i686-pc-mingw32

 * Install Matlab libraries and header files from your Windows box
   in /usr/local/i686-pc-mingw32, for example

    $ mkdir /usr/local/i686-pc-mingw32/matlab-7.1
    $ cd /usr/local/i686-pc-mingw32/matlab-7.1
    $ (cd "/mnt/Program Files/Matlab-7.1" && tar -cf- bin extern rtw simulink stateflow) | tar -xf-

 * Adjust mexopts.sh, that is change compilers and tools from 'foo' to
   'foo-i686-pc-mingw32' and change path names for libraries and header
   files. As an alternative, use Libtool to build Matlab MEX-Files.
   Libtool knows all details for cross-compiling loadable modules.
   See also my Mextool script for building MEX-files with Libtool and
   Automake/Autoconf.

--
Ralph Schleicher <http://ralph-schleicher.de>

Development * Consulting * Training
Mathematical Modeling and Simulation
Software Tools

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
linux Chris Van Kleeck 1 Feb, 2008 12:25:01
sfunction Chris Van Kleeck 1 Feb, 2008 12:25:01
simulink Chris Van Kleeck 1 Feb, 2008 12:25:00
mex Lars Barring 27 Sep, 2007 16:45:04
rssFeed for this Thread

Contact us at files@mathworks.com