MEX options when compiling with Visual Studio

天大地大妈咪最大 提交于 2020-01-05 06:50:21

问题


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?


回答1:


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);


来源:https://stackoverflow.com/questions/25998442/mex-options-when-compiling-with-visual-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!