Reputation: 1223
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
Upvotes: 3
Views: 1407
Reputation: 72463
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.
Upvotes: 4
Reputation: 2590
As far as I know, mex
just calls some other compiler without reliably setting a preprocessor macro. However, if your Matlab build script does set MEX_COMPILE_FLAG
, then your proposal will work, except that #end
needs to be #endif
.
Upvotes: 0