MATLAB: Setting up MATLAB to compile m files to dll’s for calling via C/C++ programs

c c++ compiler m file dll

Hi Everyone,
I'm new to the method of compiling m files to dll's so they can be called by C/C++ programs. I'm having general issues with setting up the Matlab compiler–I'm using Matlab 2011b. Specifically:
1. On the Matlab command line, mbuild -setup, shows a list of two compilers; lcc-win32 C 2.4.1 and Microscoft Visual C++ 2010. Is lcc-win32 C 2.4.1 the same as Matlab Compiler 4.16? The reason is that I plan to install Matlab Compiler Runtime (MCR) 7.16 and I read that the Matlab version and the compiler have to be compatible (Matlab R2011b uses compiler 4.16 and thus MCR 7.16).
2. Please let me know of any special set-up settings for the compiler. Currently, I'm using the command: mcc -t -W lib:LinearFitModelFn_lib -L C -T link:lib -h libmwsglm.mlib libmmfile.mlib LinearFitModelFn.m
I'm able to compile an m file to a c, h, dll, and lib file with the lcc compiler but I receive the following readout:
The -t switch is no longer supported; the Compiler no longer generates C/C++ source code for MATLAB functions (it generates wrapper functions instead, see the documenation for -W).
The -L switch is no longer supported; the target (-T) and wrapper (-W) switches determine the language of the generated code.
The -h switch is no longer supported; the MATLAB Compiler detects MATLAB file dependencies automatically. But see also the documentation for the -a switch. The -t switch is no longer supported; the Compiler no longer generates C/C++ source code for MATLAB functions (it generates wrapper functions instead, see the documenation for -W).
The -L switch is no longer supported; the target (-T) and wrapper (-W) switches determine the language of the generated code.
The -h switch is no longer supported; the MATLAB Compiler detects MATLAB file dependencies automatically. But see also the documentation for the -a switch.
The statement about C source code is no longer generated but rather wrapper code is a bit confusing as a c file is generated. Is this the c wrapped code? Anyway, before I ask more questions, I should first have the compiler issue corrected.
Thank you for your support; I appreciate any insight into the questions above.

Best Answer

MATLAB Compiler 4.16 is the R2011b version of the MATLAB Compiler software product, and MCR 7.16 is the MCR version associated with it.
The MATLAB Compiler product does not create C or C++ code: it creates an (encrypted) data file of threaded code (in its own internal languages) that MCR version knows how to execute at run-time.
It could be, though, that for internal purposes it needs a C compiler for an intermediate step, such as to generate appropriate machine code for a program to be able to use MCR as a DLL.
lcc is an older free C compiler that can be used to create mex files. Sometimes people run into problems because lcc is too old to know about some of the newer C constructs.
Use either compiler; it will not affect your DLL (not much anyhow.) On the other hand, the MS compiler might require that you include the MS runtime, maybe.