anyKode Marilou
ContentsIndexHome
PreviousUpNext
Create your CMEX function

Create cmex function.

A CMex function is a DLL that requires some cosmetics to be compatible with MATLAB. This section describes how to create this DLL using Visual Studio IDE, assuming you are familiar with this tool. If you are using other compiler, follow the instructions given ant translate it for your compiler : method may be similar. 

 

You can also look at sample [MarilouInstallDir]\Samples\external\MATLAB\Interface\Robot\VCxxx projects. 

 

Create project and files:

(assumes your DLL is called Robot.dll) 

Open Visual Studio and create a new Project Win32 DLL (called Robot). 

Create a Robot.def file that exports the MATLAB mexFunction

LIBRARY Robot.DLL
EXPORTS mexFunction

 

Create a CPP file that contains your cmexfunction:

void mexFunction( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[])
{
}

 

Project settings:

These settings assume $(MATLABDIR) is registered in your system. If not, replace this variable using the MATLAB absolute path.

C++ compiler options 
Description/Value 
additional include directories 
$(MARILOU_INSTALL_DIR_SDKS)\Moda\Includes
$(MATLABDIR)\extern\include 
Precompiled headers 
'No' 
Code Generation 
use runtime DLL Multitheaded (and Debug Multithreaded DLL for the debug mode) 

 

Linker options 
Description/Value 
additional libraries search path 
$(MARILOU_INSTALL_DIR_SDKS)\Moda\Libs
$(MATLABDIR)\extern\\lib\win32\microsoft\msvc60 (change msvc60 according to your compiler version) 
Additional libraries for MATLAB 
libmx.lib libmex.lib libmat.lib 
Additional libraries for MODA 
xklib-x86-win-CCC.lib moda-x86-win-CCC.lib wsock32.lib

(where CCC is your compiler
Module definition file 
set the file.def created at the start of your project 

 

Using Wizard:

cmex function can be created automatically using the MATLAB Wizard.

Documentation v4.7 (18/01/2015), Copyright (c) 2015 anyKode. All rights reserved.
What do you think about this topic? Send feedback!