MATLAB Compiler | ![]() ![]() |
Main Files
You can generate C or C++ application wrappers that are suitable for building C or C++ stand-alone applications, respectively. These POSIX-compliant main wrappers accept strings from the POSIX shell and return a status code. They are meant to translate "command-like" M-files into POSIX main applications.
POSIX Main Wrapper
The POSIX main()
function wrapper behaves exactly the same as the command/function duality mode of MATLAB. That is, any command of the form
command argument
can also be written in the functional form
command('argument')
If you write a function that accepts strings in MATLAB, that function will compile to a POSIX main wrapper in such a way that it behaves the same from the DOS/UNIX command line as it does from within MATLAB.
The Compiler processes the string arguments passed to the main()
function and sends them into the compiled M-function as strings.
For example, consider this M-file, sample.m
.
function y = sample( varargin ) varargin{:} y = 0;
You can compile sample.m
into a POSIX main application. If you call sample
from MATLAB, you get
sample hello world ans = hello ans = world ans = 0
If you compile sample.m
and call it from the DOS shell, you get
C:\> sample hello world ans = hello ans = world C:\>
The difference between the MATLAB and DOS/UNIX environments is the handling of the return value. In MATLAB, the return value is handled by printing its value; in the DOS/UNIX shell, the return value is handled as the return status code. When you compile a function into a POSIX main application, the first return value from the function is coerced to a scalar and is returned to the POSIX shell.
![]() | MEX-Files | Simulink S-Functions | ![]() |