Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Compiling mex files ouside the Matlab environment

Subject: Compiling mex files ouside the Matlab environment

From: Misael

Date: 20 Jul, 2009 16:14:02

Message: 1 of 6

Hi guys,

Does any body knows if the gnome compiler for C/C++ (gcc or g++)

 can compile mex files outside the Matlab environment?

I would like to compile mex files from a Linux Terminal as any other

C/C++ program. I am curious because, the Microsoft Visual C++ can

compile such files outside Matlab. Never done so but, the

Matlab compiler documentation shows how to do this for that

particular case.


Using the gnome compiler for Linux would help me greatly because,

I could have the flexibility to develop my mex files from my laptop;

which doesn't have Matlab. And then transfer those files to any

computer at my work to execute them. :)

-Misael

Subject: Compiling mex files ouside the Matlab environment

From: Bruno Luong

Date: 20 Jul, 2009 16:32:01

Message: 2 of 6

"Misael " <misael.diaz@upr.edu> wrote in message <h4254a$jei$1@fred.mathworks.com>...
> Hi guys,
>
> Does any body knows if the gnome compiler for C/C++ (gcc or g++)
>
> can compile mex files outside the Matlab environment?
>
> I would like to compile mex files from a Linux Terminal as any other
>
> C/C++ program. I am curious because, the Microsoft Visual C++ can
>
> compile such files outside Matlab. Never done so but, the
>
> Matlab compiler documentation shows how to do this for that
>
> particular case.
>
>
> Using the gnome compiler for Linux would help me greatly because,
>
> I could have the flexibility to develop my mex files from my laptop;
>
> which doesn't have Matlab. And then transfer those files to any
>
> computer at my work to execute them. :)
>

In principle I don't see any obstacle of compiling MEX outside MATLAB. You can invoke MEX with -v (verbose) option and duplicate the commands in stand-alone. You must have MATLAB library and include files located somewhere.

Bruno

Subject: Compiling mex files ouside the Matlab environment

From: Misael

Date: 20 Jul, 2009 16:57:02

Message: 3 of 6

Thanks,

I copied the MATLAB7/extern directory to have access to the header files and

libraries like mex.h. And then, I wrote a hello world mex file an tried to

compile it as follows in a linux terminal:

gcc hello_world.c

But the compilation failed and the compiler dumped:

undefined reference to mexPrintf.

I don't think the error comes from the source code because, I copied

it from the matlab compiler documentation.

Unfortunately, I don't know how to overcome this.

-Misael

Subject: Compiling mex files ouside the Matlab environment

From: Rune Allnor

Date: 20 Jul, 2009 17:04:29

Message: 4 of 6

On 20 Jul, 18:14, "Misael " <misael.d...@upr.edu> wrote:

> I could have the flexibility to develop my mex files from my laptop;
> which doesn't have Matlab. And then transfer those files to any
> computer at my work to execute them. :)

Develop and test your business routines on your laptop as
you would with any C(++) program. Then use MEX to develop
and test the matlab interface.

That way you can work without having matlab available,
and also be able to use your business routines elsewhere,
independent of matlab.

Rune

Subject: Compiling mex files ouside the Matlab environment

From: Bruno Luong

Date: 20 Jul, 2009 17:07:01

Message: 5 of 6

"Misael " <misael.diaz@upr.edu> wrote in message <h427ku$c1s$1@fred.mathworks.com>...
> Thanks,
>
> I copied the MATLAB7/extern directory to have access to the header files and
>
> libraries like mex.h. And then, I wrote a hello world mex file an tried to
>
> compile it as follows in a linux terminal:
>
> gcc hello_world.c
>
> But the compilation failed and the compiler dumped:
>
> undefined reference to mexPrintf.
>

Obviously you miss to include the libraries *.lib ($MATLABROOT/extern/lib/...). Take time and duplicate correctly the verbose command.

Bruno

Subject: Compiling mex files ouside the Matlab environment

From: Ralph Schleicher

Date: 21 Jul, 2009 18:16:11

Message: 6 of 6

"Misael " <misael.diaz@upr.edu> writes:

> Does any body knows if the gnome compiler for C/C++ (gcc or g++)
> can compile mex files outside the Matlab environment?

First of all, GCC means GNU Compiler Collection. It has nothing to do
with Gnome except that you can compile Gnome with GCC.

> I would like to compile mex files from a Linux Terminal as any other
> C/C++ program.

I've written a GNU Libtool wrapper to build MEX-files outside of Matlab.
It can cross-compile MEX-files, too. The latest version is available at
<http://ralph-schleicher.de/pub/matlab/mextool/mextool-2.1.tar.gz>.
Mextool is fully compatible with the rest of the GNU build system, that
is Automake, Autoconf, and Libtool. Here is an example Automake snippet:

   # Matlab MEX-files.
   MEXFILES = foo.$(MEXEXT) bar.$(MEXEXT) baz.$(MEXEXT)
   EXTRA_DIST = foo.c bar.c baz.c

   AM_MEXLDADD = ../libA/libA.la libB.la

   include $(top_srcdir)/mextool.am

That's all.

> I could have the flexibility to develop my mex files from my laptop;
> which doesn't have Matlab. And then transfer those files to any
> computer at my work to execute them. :)

You have to setup a Matlab build environment to do so, that means you
need the Matlab header files and libraries of the host system on your
build system.

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

Development * Consulting * Training
Mathematical Modeling and Simulation
Software Tools

Tags for this Thread

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.

Contact us