Setting C-MEX Compilation Options

About the C-MEX Compiler Configuration Object

Embedded MATLAB MEX provides a configuration object emlcoder.CompilerOptions for fine-tuning C-MEX compilation.

Working with the C-MEX Compiler Configuration Object

To set C-MEX compilation options, follow these steps:

  1. Define the compiler configuration object in the MATLAB workspace by issuing a constructor command, like this:

    comp_cfg = emlcoder.CompilerOptions
  2. Modify the compilation options as necessary, either at the command line or using a dialog box.

  3. Invoke emlmex with the -s option and specify the configuration object as its argument, as in this example:

    emlmex -s comp_cfg myMfile

    The -s option instructs emlmex to convert myFile.m to a C-MEX function, based on the compilation settings in comp_cfg.

Modifying Compilation Options

There are two ways to modify compilation options for emlmex:

Modifying Compilation Options at the Command Line Using Dot Notation

You can use dot notation to modify the value of one compilation option at a time, using this syntax:

configuration_object.property = value

Dot notation uses assignment statements to modify configuration object properties. For example, to change the maximum size function to inline and the stack size limit for inlined functions during C-MEX generation, enter this code at the command line:

co_cfg = emlcoder.CompilerOptions
co_cfg.InlineThreshold = 25;
co_cfg.InlineStackLimit = 4096;
emlmex -s co_cfg myFun

Modifying Compilation Options Using a Dialog Box

Besides using commands, you can modify compilation options using dialog boxes, as described in Compiler Options Dialog Box.

How emlmex Resolves Conflicting Options

emlmex resolves options from left to right, so if you use conflicting options, the rightmost one prevails. For example, assume you define a compilation configuration object as follows:

co_cfg = emlcoder.CompilerOptions
co_cfg.InlineThreshold = 20;
co_cfg.InlineThresholdMax = 100;
co_cfg.InlineStackLimit = 5000;

What happens when you execute the following command?

emlmex -s co_cfg -O disable:inline myFun

None of your inlining options take effect because the -O option overrides the -s option to disable inlining.

  


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