Using Wrapper Files

What Are Wrapper Files?

Wrapper files encapsulate, or wrap, the M-files in your application with an interface that enables the M-files to operate in a given target environment.

To provide the required interface, the wrapper does the following:

To specify the type of wrapper to generate, use the following syntax:

-W <type>

The following sections detail the available wrapper types.

Main File Wrapper

The -W main option generates wrappers that are suitable for building standalone applications. These POSIX-compliant main wrappers accept strings from the POSIX shell and return a status code. They pass these command-line strings to the M-file function(s) as MATLAB strings. They are meant to translate "command-like" M-files into POSIX main applications.

POSIX Main Wrapper

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 return status is set to 0 if the compiled M-file is executed without errors and is nonzero if there are errors.

C Library Wrapper

The -l option, or its equivalent -W lib:libname, produces a C library wrapper file. This option produces a shared library from an arbitrary set of M-files. The generated header file contains a C function declaration for each of the compiled M-functions. The export list contains the set of symbols that are exported from a C shared library.

C++ Library Wrapper

The -W cpplib:libname option produces the C++ library wrapper file. This option allows the inclusion of an arbitrary set of M-files into a library. The generated header file contains all of the entry points for all of the compiled M-functions.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS