Documentation

Package COM Components from Command Line

You can package COM components at the MATLAB® prompt or your system prompt using either of these commands.

  • deploytool invokes the Application Compiler app to execute a saved compiler project.

  • mcc invokes the MATLAB Compiler™ to create a deployable application at the command prompt.

Execute Compiler Projects with deploytool

The deploytool command has two flags that invoke one of the compiler apps to package an already existing project without opening a window.

  • -build project_name — Invoke the correct compiler app to build the project but not generate an installer.

  • -package project_name — Invoke the correct compiler app to build the project and generate an installer.

For example, deploytool -package magicsquare generates the binary files defined by the magicsquare project and packages them into an installer that you can distribute to others.

Create COM Component with mcc

The mcc command invokes MATLAB Compiler to create a COM component at the command prompt and provides fine-level control while packaging the component. It does not package the results in an installer.

A MATLAB class cannot be directly packaged into a COM object. You can, however, use a user-generated class inside a MATLAB file and build a COM object from that file. You can use the MATLAB command-line interface instead of the Library Compiler app to create COM objects. Do this by issuing the mcc command with options. If you use mcc, you do not create a project.

The following table provides an overview of some mcc options related to components, along with syntax and examples of their usage.

Action to PerformDescription
Create component that has one class.

mcc option to use: -W com

The W option with com as the type controls the generation of wrapper files, which you can use to support components.

Syntax

mcc -W 'com:<component_name>[,<class_name>[,<major>.<minor>]]'

An unspecified <class_name> defaults to <component_name>, and an unspecified version number defaults to the latest version built or 1.0, if there is no previous version.

Example

mcc -W 'com:mycomponent,myclass,1.0' -T link:lib foo.m bar.m

The example creates a COM component called mycomponent, which contains a single COM class named myclass with methods foo and bar, and a version of 1.0.

Add additional classes to a COM component.

mcc option to use: Not needed

A separate COM named <class_name> is created for each class argument that is passed.

Following the <class_name> parameter is a comma-separated list of source files that are encapsulated as methods for the class.

Syntax

class{<class_name>:[file, [file,...]]}

Example

mcc -B 'com:mycomponent,myclass,1.0' foo.m bar.m class{myclass2:foo2.m, bar2.m}

The example creates a COM component named mycomponent with two classes: myclass has methods foo and bar, and myclass2 has methods foo2 and bar2. The version is version 1.0.

Simplify the command-line input for components.

mcc option to use: -B com:

Uses the bundle.

Syntax

mcc -B '<bundle>'[:<a1>,<a2>,...,<an>]

Example

mcc -B 'com:mycomponent,myclass,1.0' foo.m bar.m

Control how each COM class uses the MATLAB Runtime.

mcc option to use: -S

By default, a new MATLAB Runtime instance is created for each instance of each COM class in the component. Use -S to change the default.

This option tells the compiler to create a single MATLAB Runtime at the time when the first COM class is instantiated. This MATLAB Runtime is reused and shared among all subsequent class instances, resulting in more efficient memory usage and eliminating the MATLAB Runtime startup cost in each subsequent class instantiation.

When using -S, note that all class instances share a single MATLAB workspace and share global variables in the MATLAB files used to build the component. Therefore, properties of a COM class behave as static properties instead of instance-wise properties.

Note

The default behavior dictates that a new MATLAB Runtime be created for each instance of a class, so when the class is destroyed, the MATLAB Runtime is destroyed as well. If you want to retain the state of global variables (such as those allocated for drawing figures, for instance), use the -S option.

Example

mcc -S -B 'com:mycomponent,myclass,1.0' foo.m bar.m

The example creates a COM component called mycomponent containing a single COM class named myclass with methods foo and bar, and a version of 1.0.

When multiple instances of this class are instantiated in an application, only one MATLAB Runtime is initialized, and it is shared by each instance.

Create subfolders needed for deployment and copy associated files to them.

mcc option to use: -d

The \src and \distrib subfolders are used to package components.

Syntax

-d foldername

Differences Between Compiler Apps and Command Line

You perform the same functions using either the compiler apps or the mcc command-line interface. The interactive menus and dialog boxes used in the compiler apps build mcc commands that are customized to your specification. As such, your MATLAB code is processed the same way as if you were packaging it using mcc.

If you know the commands for the type of application you want to deploy and do not require an installer, it is faster to execute mcc than go through the compiler app workflow.

Compiler app advantages include:

  • You can perform related deployment tasks with a single intuitive interface.

  • You can maintain related information in a convenient project file.

  • Your project state persists between sessions.

  • You can load previously stored compiler projects from a prepopulated menu.

  • You can package applications for distribution.

See Also

|

Related Topics