Reputation: 3124
I want to make a cross-platform function that has extra functionalities if compiled under MATLAB. Is there a define that can give me that information?
In other words, I'm implementing it as follows:
void f(void) {
if (x) {
(...)
}
#ifdef MATLAB
do_other_stuff();
#endif
}
and I need to have something replacing
#ifdef MATLAB
to verify that it is being compiled under matlab as a MEX function.
My '>> mex -v' outputs this:
'>> mex -v
-> mexopts.sh sourced from directory (DIR = $HOME/.matlab/$REL_VERSION)
FILE = /home/bmmo/.matlab/R2009b/mexopts.sh
----------------------------------------------------------------
-> MATLAB = /usr/matlab2009b
-> CC = gcc
-> CC flags:
CFLAGS = -ansi -D_GNU_SOURCE -fexceptions -fPIC -fno-omit-frame-pointer -pthread
CDEBUGFLAGS = -g
COPTIMFLAGS = -O -DNDEBUG
CLIBS = -Wl,-rpath-link,/usr/matlab2009b/bin/glnxa64 -L/usr/matlab2009b/bin/glnxa64 -lmx -lmex -lmat -lm -lstdc++
arguments = -DMX_COMPAT_32
-> CXX = g++
-> CXX flags:
CXXFLAGS = -ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer -pthread
CXXDEBUGFLAGS = -g
CXXOPTIMFLAGS = -O -DNDEBUG
CXXLIBS = -Wl,-rpath-link,/usr/matlab2009b/bin/glnxa64 -L/usr/matlab2009b/bin/glnxa64 -lmx -lmex -lmat -lm
arguments = -DMX_COMPAT_32
-> FC = g95
-> FC flags:
FFLAGS = -fexceptions -fPIC -fno-omit-frame-pointer
FDEBUGFLAGS = -g
FOPTIMFLAGS = -O
FLIBS = -Wl,-rpath-link,/usr/matlab2009b/bin/glnxa64 -L/usr/matlab2009b/bin/glnxa64 -lmx -lmex -lmat -lm
arguments = -DMX_COMPAT_32
-> LD = gcc
-> Link flags:
LDFLAGS = -pthread -shared -Wl,--version-script,/usr/matlab2009b/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined
LDDEBUGFLAGS = -g
LDOPTIMFLAGS = -O
LDEXTENSION = .mexa64
arguments =
-> LDCXX =
-> Link flags:
LDCXXFLAGS =
LDCXXDEBUGFLAGS =
LDCXXOPTIMFLAGS =
LDCXXEXTENSION =
arguments =
----------------------------------------------------------------
Thanks in advance.
Upvotes: 2
Views: 844
Reputation: 114786
Try running
>> mex -v
in your Matlab and inspect the COMPFLAGS
it lists.
On my machine I see /DMATLAB_MEX_FILE
that is a const MATLAB_MEX_FILE
is being defined. I guess this is the case for other platforms, but its worth checking in advance.
Upvotes: 4