From: Michael Bieri on
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
From: Ashish Uthama on
On Mon, 15 Mar 2010 16:31:05 -0400, Michael Bieri <mibieri(a)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?
From: Michael Bieri on
"Ashish Uthama" <first.last(a)mathworks.com> wrote in message <op.u9mmcea8a5ziv5(a)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!