Configuring Code Generation
To control and configure the code generation process, there are many parameters
and settings. These settings control attributes such as the output build type (MEX,
lib, dll, or exe) and C versus C++ language. Other configuration settings enable you
to customize the generated code according to specific needs, such as readability,
performance, and external code integration.
You can modify the configuration settings in the code generation configuration
object from the app or at the command line. You can create the configuration object
by using coder.config. Open the object in the
editing app using open.
Functions
coder.config | Create code generation configuration objects |
Code Configuration Settings
| Build type | Output to build from generated C/C++ code |
| Language | Language to use in generated code |
| Language standard | Language standard to use for the generated code |
| Custom output file | Name of code generation output file |
| Generate code only | Generation of only source code |
| Verification mode | Code verification mode |
| Build folder | Folder type for files generated during build process |
| Build folder path | Folder path for files generated during build process |
| Working folder | Current working folder type for build process |
| Working folder path | Current working folder path for build process |
| Enable responsiveness to CTRL+C and graphics refreshing | Responsiveness checks |
| Keep extrinsic calls | Extrinsic function call support |
| Check memory integrity | Memory integrity checking |
| Saturate on integer overflow | Integer overflow support |
| Support only purely-integer numbers | Detection of floating-point code |
| Support nonfinite numbers | Support for nonfinite values |
| Loop unrolling threshold | Threshold on the number of iterations that determines whether to automatically
unroll a for-loop and a parfor-loop |
| Preserve input data for entry-point functions | Whether to protect entry-point input data from modification |
| Qualify C restrict function arguments | Annotate function declarations with the restrict keyword |
| Enable OpenMP library if possible | Parallelization of parfor-loops |
| Enable automatic parallelization | Automatic parallelization of for loops |
| Maximum number of CPU threads | Maximum number of CPU threads to run parallel for-loops |
| Leverage target hardware instruction set extensions | SIMD instruction set for target hardware |
| FMA | Whether to use SIMD instructions for fused multiply add operations |
| Inline strategy for user written MATLAB functions | Control inlining between user-written functions |
| Inline strategy for MathWorks written MATLAB functions | Control inlining between MathWorks functions |
| Inline strategy for calls between MathWorks functions and user functions | Control inlining between user-written functions and MathWorks functions |
| Optimize reductions | Generate SIMD code for reduction operations | Parallelize for-loops performing reduction operations |
| Hardware SIMD acceleration | Level of SIMD intrinsics |
| Global data synchronization mode | Global data synchronization mode |
| Enable variable-sizing | Variable-size array support |
| Enable dynamic memory allocation | Enable dynamic memory allocation for fixed- and variable-size arrays |
| Dynamic memory allocation threshold | Size threshold for dynamic memory allocation of variable-size arrays |
| Enable dynamic memory allocation for fixed-sized arrays | Dynamic memory allocation for fixed-size arrays |
| Dynamic memory allocation interface | Dynamically allocated array at generated function interface |
| Array layout | Row-major array layout |
| Preserve array dimensions | N-dimensional indexing |
| Stack usage max | Maximum stack usage per application |
| Generate re-entrant code | Multi-instance, reentrant code |
| Preserve unused fields and properties | Preserve unused class properties or structure fields in the generated C/C++ code |
| Generated file partitioning method | File partitioning mode |
| Large constant generation | Whether to write large deep learning constants to binary data files |
| Large constant threshold | Threshold above which the code generator writes DNN constants to binary data files |
| Include comments | Comments in generated code |
| Comment style | Comment style in the generated code |
| MATLAB source code as comments | Inclusion of MATLAB source code as comments in generated code |
| MATLAB source code comment line numbers | Include line numbers of MATLAB source code as comments in the generated code |
| MATLAB function help text | MATLAB function help text in function banner |
| Requirement summaries as comments | Include requirements links as comments |
| Convert if-elseif-else patterns to switch-case statements | Conversion of if-elseif-else patterns to
switch-case statements |
| Preserve extern keyword in function declarations | Preservation of the extern keyword in function
declarations |
| Use signed shift left for fixed-point operations and multiplication by powers of 2 | Replacement of multiplications by powers of two with signed left bitwise shifts |
| Allow right shifts on signed integers | Signed right bitwise shifts in generated code |
| Parentheses | Parenthesization level in the generated code |
| Maximum identifier length | Maximum number of characters in generated identifiers |
| Header guard style | Style of preprocessor directive in generated code |
| Indent style | Style for placement of braces in the generated code |
| Indent size | Number of characters per indentation level |
| Column limit | Maximum number of columns before a line break in the generated code |
| Data type replacement | Data type replacement in generated code |
| Enable custom data type replacement | Custom names for data types in generated code |
| Import custom types from external header files | Whether to import type definition from external header files |
| Header files | External header files that contain custom type definitions |
| Global variables | Custom identifier format for global variable identifiers |
| Global types | Custom identifier format for global type identifiers |
| Field name of global types | Custom identifier format for field names in global type identifiers |
| Local functions | Custom identifier format for local function identifiers |
| Local temporary variables | Custom identifier format for local temporary variable identifiers |
| Constant macros | Custom identifier format for constant macro identifiers |
| EMX array types | Custom identifier format for EMX array types |
| EMX array utility functions | Custom identifier format for EMX array utility functions |
| Generated source and header file name format | File name customization macro |
| Code generation template file | Code generation template for file and function banners |
| Select code format tool to use | Formatting tool for generated code |
| Control use of clang format configuration | Control generation of clang-format file |
| Enable C/C++ compiler debug mode | C compiler debugging mode |
| Generate run-time error checks | Run-time error detection and reporting in generated code |
| Show verbose compiler output | Code generation progress display |
| Always create a report | Code generation report |
| Report differences from MATLAB | Potential differences reporting |
| Highlight potential data type issues | Highlighting of potential data type issues in the code generation report |
| Highlight potential row-major issues | Potential row-major layout issues |
| Highlight potential issues resulting from implicit expansion | Highlight potential implicit expansion issues |
| Highlight potential issues in use of coder.loop functions | Highlight potential loop control issues |
| Generate static code metrics report | Static code metrics report |
| Generate code replacements report | Code replacement report |
| Automatically launch a report if one is generated | Automatic open of code generation report |
| Export report information to variable | Name of variable containing code generation report information |
| Enable source-level debugging for SIL or PIL | Debugging of generated code during a SIL or PIL execution |
| Check constant inputs | Constant input checking mode for a SIL or PIL execution |
| Synchronize global data | Global data synchronization mode for a SIL or PIL execution |
| Enable entry point execution profiling | Execution time profiling during a SIL or PIL execution |
| Enable function execution profiling | Execution time profiling of functions called within entry-point functions during a SIL or PIL execution |
| Specify profiling save options | Collection and storage of execution-time measurements |
| Enable entry point stack profiling | Stack usage profiling during a SIL or PIL execution |
| Enable C/C++ code coverage | Analysis of C/C++ code coverage |
| Enable execution profiling | Instrumentation for profiling |
| Code replacement library | Code replacement library for generated code |
| Use built-in FFTW library | Generate code that uses the FFTW library shipped with MATLAB |
| Custom FFT library callback | Callback class for FFTW library calls |
| Custom BLAS library callback | BLAS callback class |
| Custom LAPACK library callback | LAPACK callback class |
| Use precompiled libraries | Whether to use precompiled libraries in generated code |
| Source file | Code to appear near the top of generated .c or
.cpp files |
| Header file | Custom code that appears at top of generated C/C++ header files |
| Initialize function | Custom code to include in the generated initialize function |
| Terminate function | Code that appears in the generated terminate function |
| Additional include directories | Include folders to add to include path for compiling generated code |
| Additional source files | Source files to compile and link with the generated code |
| Additional libraries | Static library files to link with the generated code |
| Post-code-generation command | Command to customize build processing |
| Reserved names | Names that code generator must not use for functions or variables |
| Hardware board | Name of hardware board |
| Production Device Details: Device vendor | Manufacturer of production hardware |
| Production Device Details: Device type | Type of production hardware |
| Production Device Details: char | Length in bits of the C char data type |
| Production Device Details: short | Length in bits of the C short data type |
| Production Device Details: int | Length in bits of the C int data type |
| Production Device Details: long | Length in bits of the C long data type |
| Production Device Details: long long | Length in bits of the C long long data type |
| Production Device Details: float | Length in bits of the C floating-point data type |
| Production Device Details: double | Length in bits of the C double data type |
| Production Device Details: machine word | Microprocessor native word size |
| Production Device Details: pointer | Length in bits of pointer data |
| Production Device Details: size_t | Length in bits of size_t data |
| Production Device Details: ptrdiff_t | Length in bits of ptrdiff_t data |
| Production Device Details: Byte ordering | Significance of the first byte of a data word |
| Production Device Details: Shift right on a signed integer as an arithmetic shift | Implementation of signed integer right shift as arithmetic right shift |
| Production Device Details: Enable long long | Long long data type support |
| Production Device Details: Largest atomic integer size | Largest atomic integer size for production hardware |
| Production Device Details: Largest atomic floating-point size | Largest atomic floating-point size for production hardware |
| Production Device Details: Signed integer division rounds to | Rounding for division of two signed integers |
| Target Device Details: Device vendor | Manufacturer of test hardware |
| Target Device Details: Device type | Type of test hardware |
| Test Device Details: char | Length in bits of the C char data type |
| Test Device Details: short | Length in bits of the C short data type |
| Test Device Details: int | Length in bits of the C int data type |
| Test Device Details: long | Length in bits of the C long data type |
| Test Device Details: long long | Length in bits of the C long long data type |
| Test Device Details: float | Length in bits of the C floating-point data type |
| Test Device Details: double | Length in bits of the C double data type |
| Test Device Details: machine word | Microprocessor native word size |
| Test Device Details: pointer | Length in bits of pointer data |
| Test Device Details: size_t | Length in bits of size_t data |
| Test Device Details: ptrdiff_t | Length in bits of ptrdiff_t data |
| Test Device Details: Byte ordering | Significance of the first byte of a data word |
| Test Device Details: Shift right on a signed integer as an arithmetic shift | Implementation of signed integer right shift as arithmetic right shift |
| Test Device Details: Enable long long | Long long data type support |
| Test Device Details: Largest atomic integer size | Largest atomic integer size for test hardware |
| Test Device Details: Largest atomic floating-point size | Largest atomic floating-point size for test hardware |
| Test Device Details: Signed integer division rounds to | Rounding for division of two signed integers |
| Toolchain | Toolchain to use for building a C/C++ library or executable program |
| Custom Toolchain Options | Custom settings for tools in selected toolchain |
| Build configuration | Compiler optimization or debug settings for toolchain |
| Test Hardware is the same as production hardware | Equivalence of production and target hardware characteristics |
| C++ namespace | Namespace name for generated C++ code |
| Interface style | Interface style for generated C++ code |
| C++ interface class name | Interface class name for generated C++ code |
| Generate C++ namespaces from MATLAB namespaces | Generate C++ namespaces for MATLAB namespaces |
| Namespace for MathWorks code | Place C++ code generated for MathWorks code in a separate namespace |
| Generate C++ classes from MATLAB classes | Generate C++ classes for MATLAB classes |
| Generate C++ enum class from MATLAB enumeration | Whether to generate C++ enumeration classes for MATLAB enumerations |
| Casting mode | Data type casting level |
| Constant folding timeout | Maximum number of instructions to be executed by the constant folder |
| Compile-time recursion limit | Maximum number of function specializations for compile-time recursion |
| Automatically run the initialize function | Automatically run the initialize function |
| Initialize function required | Initialize function generation |
| Terminate function required | Terminate function generation |
| Generate justification comments for known MISRA violations | Add annotations to suppress known MISRA/AUTOSAR violations |
| Generate example main | Example C/C++ main file generation |
| Preserve variable names | Variable names to preserve in the generated code |
| Echo expressions without terminating semicolons | Expression echoing |
| Generate makefile | Makefile generation |
| Automatically introduce extrinsic calls | Automatic extrinsic function calls |
| Simplify array indexing | Strength reduction optimization |
| Use memcpy for vector assignment | Whether to enable memcpy optimization |
| Memcpy threshold (bytes) | Minimum size for memcpy or memset
optimization |
| Use memset to initialize floats and doubles to 0.0 | Assignment of float and double zero with memset |
| Constant inputs | Constant input checking mode |
| Use JIT compilation for build type of MEX | Just-in-time (JIT) compilation mode |
| Generate nonfinite support files if used | Generate support files for nonfinite data only if nonfinite data is used |
| Pass structures by reference to entry-point functions | Pass structures by reference |
| Always generate a default case for switch | Default case for all switch statements |
| Enable code traceability | Traceability in code generation report |
| Use Embedded Coder features | Whether to use Embedded Coder features |
| Enable implicit expansion | Implicit expansion capabilities in generated code |
| Enable automatic parallelization reporting | Reporting for automatic parallelization of for
loops |
| Enable run-time recursion | Run-time recursion support |
| Cache dynamic array data | Dynamic array optimization |
| SIL/PIL Verbosity | Display communication I/O information during SIL or PIL execution |
| SIL/PIL profiling metrics | PMU metric |
Objects
coder.MexCodeConfig | Configuration parameters for MEX function generation from MATLAB code |
coder.CodeConfig | Configuration parameters for C/C++ code generation from MATLAB code |
coder.EmbeddedCodeConfig | Configuration parameters for C/C++ code generation from MATLAB code with Embedded Coder |
coder.HardwareImplementation | Hardware-specific configuration parameters for C/C++ code generation from MATLAB code |
coder.hardware | Create hardware board configuration object for C/C++ code generation from MATLAB code |
coder.ReplacementTypes | Configuration parameter to specify custom names for MATLAB built-in data types in C/C++ code generation |
Topics
Build Configuration Basics
- Configure Code Generation and Build Settings
Configure code generation and build configuration parameters at the command line or in the MATLAB® Coder™ app. - Paths and File Infrastructure Setup
Specify location of custom code. - Build Process Support for File and Folder Names
Troubleshoot build process errors that occur when file system issues prevent file processing. - Share Build Configuration Settings
Export project settings to a code generation configuration object or import the settings into a project. - Specify Code Configuration Parameters Interactively
Configure the code generation process by using the Code Generation Settings dialog box.
Specific Build Options
- Understand and Control Partitioning of the Generated Code
Understand how file partitioning method and inlining settings interact to control the partitioning of the generated code. - Change Language Standard Used for Code Generation
The code generator uses the language standard that you specify in the build settings.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)