1

For some reasons I have to compile my MEX files under the Visual studio environment. There are many tutorials and my MEX files are working fine. However, there are a few MEX options, say -largeArrayDims in mex options, which I do not know where to turn on under the VS environment. Can anyone offer help?

chappjc
  • 30,359
  • 6
  • 75
  • 132
Fontaine007
  • 577
  • 2
  • 8
  • 18

1 Answers1

2

The -largeArrayDims option is a switch to the mex command in MATLAB that simply indicates not to define MX_COMPAT_32. So, in Visual Studio, you don't have to do anything since this is not defined by default. If you want the opposite behavior (-compatibleArrayDims), then 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 a property sheet to set all the necessary settings for building a MEX file (library dependencies, headers, MEX-file extension, etc.). A single property sheet that works automatically for either 32-bit or 64-bit MATLAB can be found at GitHub.

Add the property sheet to each build configuration for the MEX project in the Property Manager (right click on the configuration such as Debug | x64 and select "Add Existing Property Sheet". See this post for detailed instructions.

A few additional notes:

  1. I prefer to use /EXPORT:mexFunction instead of a .def file. With a single exported function, this is much simpler.
  2. The property sheet makes a manifest file, but it's really not necessary.
  3. I include libut.lib, which provides a few nice functions for detecting a break (CTRL-C) from within a MEX file. The relevant declarations (although this is way off topic here):
// prototype the break handling functions in libut (C library)
extern "C" bool utIsInterruptPending();
extern "C" void utSetInterruptPending(bool);
Community
  • 1
  • 1
chappjc
  • 30,359
  • 6
  • 75
  • 132
  • Thanks and this is very helpful. So the process is, I make an XML file and incorporate it in the configuration? Does the mex command execute the same process when calling the CL compiler (or Linker)? – Fontaine007 Sep 23 '14 at 17:18
  • @JasonYuan The content of the files is XML, yes, but it should be saved `with a .props extension`. The `mex` command essentially configures the build (compile and link) the same way. Just try the `-v` switch when you run `mex` to see the different command lines used. These property sheets set things up to do the same thing from Visual Studio. – chappjc Sep 23 '14 at 17:59