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
can also be written in the functional form
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
.
You can compile sample.m
into a POSIX main application. If you call sample
from MATLAB, you get
If you compile sample.m
and call it from the DOS shell, you get
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 | ![]() |