MEX options when compiled with Visual Studio

For some reason I have to compile the MEX files in the Visual Studio environment. There are many tutorials and my MEX files are working fine. However, there are several variants of MEX, for example -largeArrayDims

in mex

that I don't know where to include in the VS environment. Can anyone offer help?

+1


source to share


1 answer


A parameter -largeArrayDims

is a switch to a command mex

in MATLAB that simply indicates not to be defined MX_COMPAT_32

. This way, in Visual Studio, you don't need to do anything as it is undefined by default. If you require the opposite behavior ( -compatibleArrayDims

), define MX_COMPAT_32

in the "Preprocessor" section. From tmwtypes.h:

tmwtypes.h

#ifdef MX_COMPAT_32
typedef int mwSize;
typedef int mwIndex;
typedef int mwSignedIndex;
#else
typedef size_t    mwSize;         /* unsigned pointer-width integer */
typedef size_t    mwIndex;        /* unsigned pointer-width integer */
typedef ptrdiff_t mwSignedIndex;  /* a signed pointer-width integer */
#endif

      

In general, it is convenient to use the property sheet to set all the necessary parameters to create a MEX file (library dependencies, headers, MEX file extension, etc.). A separate property sheet that works automatically for 32-bit or 64-bit MATLAB can be found on GitHub .



Add a property sheet to each build configuration for a MEX project in the Property Manager (right click on a configuration such as Debug | x64

and select “Add Existing Property Sheet.” See this post for detailed instructions .

A few additional notes:

  • I prefer to use /EXPORT:mexFunction

    the .def file instead. With one exported function, this is much easier.
  • The property sheet creates a manifest file, but that really isn't necessary.
  • I include libut.lib, which provides some nice functions for detecting interrupt (CTRL-C) from a MEX file. Relevant declarations (although this is not the case here):
// prototype the break handling functions in libut (C library)
extern "C" bool utIsInterruptPending();
extern "C" void utSetInterruptPending(bool);

      

+2


source







All Articles