Thread Subject: Compile a Program with mex.h without mex

Subject: Compile a Program with mex.h without mex

From: Michael Bieri

Date: 15 Mar, 2010 20:31:05

Message: 1 of 3

Hello

I'm writing a C program that can be called from matlab as well as from a console. That means, I have a main(...) as well as a mexFunction(...).

I have no problems when compiling with mex, but I get linker errors when I try to compile it with another C compiler like gcc. This of course happens, because some libs are missing. But which libs does the compiler need to succeed? I tried several folders in the MATLAB/extern area, but had again linker errors. Is it possible at all to compile a file containing calls to mex.h without mex?

Notice: Functions of mex.h are only called from mexFunction(...) and therefore only if the program is called from matlab. If the program is called from the console via main(...), there's no need for any mex code. So it's only an issue of compiling.

Regards
Michael

Subject: Compile a Program with mex.h without mex

From: Ashish Uthama

Date: 15 Mar, 2010 20:39:40

Message: 2 of 3

On Mon, 15 Mar 2010 16:31:05 -0400, Michael Bieri <mibieri@ee.ethz.ch>
wrote:

> Hello
>
> I'm writing a C program that can be called from matlab as well as from a
> console. That means, I have a main(...) as well as a mexFunction(...).
>
> I have no problems when compiling with mex, but I get linker errors when
> I try to compile it with another C compiler like gcc. This of course
> happens, because some libs are missing. But which libs does the compiler
> need to succeed? I tried several folders in the MATLAB/extern area, but
> had again linker errors. Is it possible at all to compile a file
> containing calls to mex.h without mex?
>
> Notice: Functions of mex.h are only called from mexFunction(...) and
> therefore only if the program is called from matlab. If the program is
> called from the console via main(...), there's no need for any mex code.
> So it's only an issue of compiling.
>
> Regards
> Michael

try the mex -v option to figure out how MATLAB calls the compiler.

Maybe you can switch contents of the code on/off using #def's?

Subject: Compile a Program with mex.h without mex

From: Michael Bieri

Date: 15 Mar, 2010 20:51:07

Message: 3 of 3

"Ashish Uthama" <first.last@mathworks.com> wrote in message <op.u9mmcea8a5ziv5@uthamaa.dhcp.mathworks.com>...
> Maybe you can switch contents of the code on/off using #def's?

This is the solution! Why didn't I find this by myself instead of spending two hours of trial and error..?

Thank you!

Tags for this Thread

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.

rssFeed for this Thread

Contact us at files@mathworks.com