Code generation options, specified as an option value or a space-delimited list of
option values. You can enter option values in any
order. If options conflict, the rightmost option prevails.
Specify Code Configuration Object
To specify a code configuration object, use the -config option.
You can use this object by itself or in conjunction with other option values. See
Configure Code Generation and Build Settings. The code generator gives precedence to the
options that you specify with the codegen function over the
options that you specify by using a code configuration object.
| Option Value | Description |
|---|
-config
configObject | Specify the configuration object that contains the code
generation settings. To create a code configuration object, use the
coder.config function. For
example, to create a code configuration object for a static library, use
this
command: Then,
pass the created object to the codegen. For
example: |
Control Generated Code Language
This table shows the options that control the language of the generated code. By
default, the code generator produces C code compatible with the C99 (ISO) language
standard. If you generate C++ code, the code generator produces C++ code compatible
with the C++11 (ISO) language standard by default.
If you generate C code, C++ language standards are not supported. If you generate
C++ code but specify a C language standard, the code generator uses the C math
libraries available in the selected C standard and C++03 language features. For
details about the supported language standards, see Change Language Standard Used for Code Generation.
| Option Value | Description |
|---|
-lang:c | Generate C code. |
-lang:c++ | Generate C++ code. |
-std:c89/c90
| Generate code compatible with the C89/90 (ANSI) language
standard. |
-std:c99
| Generate code compatible with the C99 (ISO) language standard.
This language standard is the default when you generate C
code. |
-std:c++03 | Generate code compatible with the C++03 (ISO) language
standard. |
-std:c++11 | Generate code compatible with the C++11 (ISO) language standard.
This language standard is the default when you generate C++
code. |
-std:c++14 | Generate code compatible with the C++14 (ISO) language
standard. |
-std:c++17 | Generate code compatible with the C++17 (ISO) language
standard. |
-std:c++20 | Generate code compatible with the C++20 (ISO) language
standard. |
Control Output Type
This table shows the options that control the type of code produced by the code
generator. By default, the code generator produces a MEX function and builds the
generated code.
| Option Value | Description |
|---|
-config:dll | Generate a dynamic C/C++ library. |
-config:exe | Generate a C/C++ executable. |
-config:lib | Generate a static C/C++ library. |
-config:mex | Generate a MEX function. |
-c | Generate source code only. The code generator does not invoke the
make command or build object code. For example, to
produce a static C library for function foo and
generate source code without building the generated code, use this
command:
|
-jit | Use just-in-time (JIT) compilation to generate a JIT MEX
function, which contains an abstract representation of the MATLAB code. JIT compilation can speed up MEX function generation.
You can only use this option when you generate a MEX function. This option
is not compatible with some code generation options, such as including
custom code or using the OpenMP library. See Speed Up MEX Generation by Using JIT Compilation. |
Specify Global Variables
Use the -globals option to specify global variables at the
command line. You can also define and initialize global variables in the MATLAB workspace. See Generate Code for Global Variables.
| Option Value | Description |
|---|
-globals
globalArray | Define and initialize the global variables used in the
MATLAB functions for which you generate
code. globalArray
is a cell array of global variable names and initial values. This cell
array has the format
{global1,value1,global2,value2,...}.
For
example:
Alternatively,
specify the global variable types by using the coder.typeof function. In this
case, the cell array you pass to the -globals option
has the format
{global1,{type1,value1},global2,{type2,value2},...}.
For
example: |
Specify Optimizations
This table shows the options that specify optimizations in the generated code. For
additional strategies that you can use to optimize the generated code, see Optimize Generated C/C++ and MEX Code.
| Option Value | Description |
|---|
-O enable:inline
-O
disable:inline
| Enable or disable function inlining in the generated code. By
default, the code generator uses inlining. To learn more about function
inlining, see Control Inlining to Fine-Tune Performance and Readability of Generated Code. Always inlining function
calls causes the code generation optimizations to process more code, and
therefore, might increase code generation time. |
-O enable:openmp
-O
disable:openmp
| Enable or disable the use of the OpenMP library in the generated
code. If you enable this optimization and the OpenMP library is available,
the code generator generates parfor-loops that can run on
multiple threads. By default, the code generator uses the OpenMP library, if
it is available. If use disable the OpenMP optimization or the
OpenMP library is not available, the code generator treats
parfor-loops like for-loops and
generates code that runs on a single thread. See Control Compilation of parfor-Loops. |
-rowmajor | Generate code that uses row-major array layout. By default, the
code generator uses column-major array layout. For more information, see
Generate Code That Uses Row-Major Array Layout. |
Specify Debugging Options
This table shows the options that you can use to debug the generated code and the
code generation process. Before generating standalone code or an accelerated MEX
function, it is a best practice to check from compliance issues in your MATLAB code by generating and running a MEX function. See Check for Issues in MATLAB Code Using MEX Functions.
| Option Value | Description |
|---|
-g | Enable the debug mode for the C/C++ compiler. If you enable debug
mode, the code generator disables some of the optimizations that the
compiler uses, which can make code generation faster. However, the
generated code may execute more slowly. |
-profile | Profile the generated MEX function by using the MATLAB Profiler. See Profile MEX Functions by Using MATLAB Profiler. |
-report | Produce a code generation report. If you do not specify this
option, codegen produces a report only if error or
warning messages occur or if you specify the
-launchreport option. If you have
Embedded Coder®, this option also enables production of the Code
Replacements report. |
-reportinfo info | Export information about code generation to the variable
info in the base MATLAB workspace. See Access Code Generation Report Information Programmatically. |
-silent | Enable this optimization to suppress messages when code generation
succeeds without warning. This option does not suppress warning and error
messages. |
-test testFile | Run testFile and
replace calls to the original MATLAB function with calls to the MEX function. Using this option
is the same as running coder.runTest. This option is supported only when
generating MEX functions. If you have an Embedded Coder license, you can also use this option when you generate code
for software-in-the-loop (SIL) or processor-in-the-loop (PIL)
verification. See Code Verification Through Software-in-the-Loop and Processor-in-the-Loop Execution (Embedded Coder). |
-v | Show the code generation status and target build log
messages. |
Control Name and Location of Generated Files
This table shows the options that you can use to change the default base name and
location of the files produced by the code generator.
| Option Value | Description |
|---|
-d folder | Store generated files in the absolute or relative path specified by
folder. The folder name
must not contain:
Spaces, which can result in code generation failures in certain
operating system configurations Characters that are not 7-bit ASCII characters, such as Japanese
characters The asterisk (*), question mark
(?), dollar sign ($), or
number sign (#) symbols
If the folder specified by
folder does not exist, the
code generator creates it. |
-o basename | Generate MEX, library, and executable files with the base name
basename. The base name
must not contain spaces, which can result in code generation failures in
certain operating system configurations. If you generate a MEX function,
basename must be a valid
MATLAB function name. |
Modify Code Generation Path
Use the -I option to instruct the code generator to search
additional folders for your MATLAB function or custom code files.
| Option Value | Description |
|---|
-I path | Adds path to the
beginning of the code generation path. When the code generator searches for
MATLAB functions or custom C/C++ files, it searches the code
generation path first. Because it does not search for classes on the code
generation path, classes must be on the MATLAB search path. For more information, see Paths and File Infrastructure Setup. If the path contains characters that are not 7-bit ASCII,
such as Japanese characters, the code generator may not find the files on
this path. To include multiple paths, use -I
before each path you want to include. Pass paths as character vectors or
strings. For example:
|
Export Generated Code
This table shows the options that you can use to transfer the generated code or
the code generation settings to another development environment or to the MATLAB
Coder app.
| Option Value | Description |
|---|
-package zipFile | Package generated standalone code and its dependencies into a
compressed ZIP file with the name
zipFile. You can use the
ZIP file to relocate, unpack, and rebuild the code files in another
development environment. Using this option is the same as
using the packNGo
function. |
-toproject
projectFile | Save the names of the entry-point functions,
-args and -nargout specifications,
codegen options, and
any advanced syntaxes to a MATLAB
Coder project file named
projectFile. Use this
command if you want to transfer the codegen
specifications to the MATLAB
Coder app. You can also generate code using this project file by
using this
command:
See Convert codegen Command to Equivalent MATLAB Coder Project. |
Perform Numeric Conversion
This table shows the options that you can use to perform numeric conversion of
MATLAB code. You must have a Fixed-Point Designer™ license to use these options. These options are not supported
entry-point functions in namespaces.
| Option Value | Description |
|---|
-config:single | Generate single-precision MATLAB code. |
-double2single
singleConfig | Generate single-precision MATLAB code using the settings that you specify in
singleConfig, which must
be a coder.SingleConfig
object. The code generator produces files in the folder
codegen/fun/single, where
fun is the name of the
entry-point function. If you specify this option and instruct
the code generator to generate standalone code, the code generator also
generates single-precision C/C++ code in the folder
codgen/outputType/subfolder,
where:
For more information, see Generate Single-Precision MATLAB Code. |
-float2fixed
float2fixedConfig | Generate fixed-point code using the settings that you specify in
float2fixedConfig, which
must be a coder.FixPtConfig
object. If you specify this option and instruct the code
generator to generate standalone code, the code generator produces
fixed-point C/C++ code. The code generator produces files in the folder
codegen/outputType/fun_fixpt,
where fun is the name of the
entry-point function and
outputType is:
mex for MEX functions
exe for embeddable C/C++ executables
lib for embeddable C/C++ libraries
dll for C/C++ dynamic libraries
If you specify this option and do not generate
standalone code, the code generator produces fixed-point MATLAB code in the folder
codegen/fun/fixpt. To
use this option, you must specify a test file by using the
TestBenchName property of the
float2fixedConfig
object. For more information, see Convert MATLAB Code to Fixed-Point C Code. |
-singleC | Generate single-precision C/C++ code. For more information, see
Generate Single-Precision C Code at the Command Line. |
Generate CUDA Code
This table shows the options that you can use when you generate CUDA® code from MATLAB code. You must have a GPU Coder™ license to use these options.
| Option Value | Description |
|---|
-config gpuconfig | Specify the configuration object that contains the CUDA code generation settings. To generate this configuration
object, use the function coder.gpuConfig (GPU Coder). See Generate Code Using the Command Line Interface (GPU Coder). |
-gpuprofile | Profile the generated code by using the GPU
performance analyzer. To
generate and profile CUDA code using a single command, run codegen
with both the -gpuprofile and -test
options. To profile non-MEX targets, you must have an
Embedded Coder license. For more information, see GPU
Performance Analyzer (GPU Coder). |