Mex compilation macro

c++, matlab, mex

Solution

You can use the macro `MATLAB_MEX_FILE` for this. To get mex.h to work properly, this macro must be defined if and only if the compiled object will eventually be linked into a mex file. So the `mex` command makes sure to always define it when it calls the compiler.

Problem

I wish to include a certain header file only when my code is compiled via the mex command in Matlab. If it's compiled directly with Visual Studio I do not want it included. Is there a macro that can help with that? I'd like to do something of this sort: ``` #ifdef MEX_COMPILE_FLAG #include "mexDependent.h" #end ```

Original source