coder.CodeConfig

Configuration parameters for C/C++ code generation from MATLAB code

Description

A coder.CodeConfig object contains the configuration parameters that codegen uses for generating a static library, a dynamically linked library, or an executable program. Pass the object to the codegen function by using the -config option.

Creation

Description

example

cfg = coder.config(build_type) creates a code generation configuration object for the specified build type, which can be a static library, a dynamically linked library, or an executable program. If the Embedded Coder® product is not installed, it creates a coder.CodeConfig object. Otherwise, it creates a coder.EmbeddedCodeConfig object.

cfg = coder.config(build_type, 'ecoder', false) creates a coder.CodeConfig object for the specified output type even if you have Embedded Coder installed.

Input Arguments

expand all

Output to build from generated C/C++ code, specified as one of the values in this table.

ValueDescription
'LIB'Static library
'DLL'Dynamically linked library
'EXE'Executable program

Properties

expand all

Compiler optimization or debug settings for toolchain, specified as one of the values in this table.

ValueDescription
'Faster Builds'

Optimizes the build for shorter build times.

'Faster Runs'

Optimizes the build for faster running executables.

'Debug'

Optimizes the build for debugging.

'Specify'

Enables the CustomToolchainOptions property for customization of settings for tools in the selected toolchain. If the Toolchain property is set to 'Automatically locate an installed toolchain', then setting BuildConfiguration to 'Specify' changes Toolchain to the located toolchain.

Code replacement library for generated code, specified as one of the values in this table:

ValueDescription
'None'

This value is the default value.

Does not use a code replacement library.

Named code replacement library

Generates calls to a specific platform, compiler, or standards code replacement library. The list of named libraries depends on:

  • Installed support packages.

  • System target file, language, standard math library, and device vendor configuration.

  • Whether you created and registered code replacement libraries, using the Embedded Coder product.

Compatible libraries depend on these parameters:

  • TargetLang

  • TargetLangStandard

  • ProdHWDeviceType in the hardware implementation configuration object.

Embedded Coder offers more libraries and the ability to create and use custom code replacement libraries.

MATLAB® Coder™ generates the minimal set of #include statements for header files required by the selected code replacement library.

Before setting this parameter, verify that your compiler supports the library that you want to use. If you select a parameter value that your compiler does not support, compiler errors can occur.

Note

MATLAB Coder software does not support TLC callbacks.

Maximum number of function specializations for compile-time recursion, specified as a positive integer. To disallow recursion in the MATLAB code, set CompileTimeRecursionLimit to 0. The default compile-time recursion limit is large enough for most recursive functions that require this type of recursion. If code generation fails because of the compile-time recursion limit, and you want compile-time recursion, try to increase the limit. Alternatively, change your MATLAB code so that the code generator uses run-time recursion. See Compile-Time Recursion Limit Reached.

Maximum number of instructions that the constant folder executes. In some situations, code generation requires specific instructions to be constant. If constant folding stops before these instructions are constant-folded, code generation fails. In this case, increase the value of ConstantFoldingTimeout.

See MATLAB Coder Optimizations in Generated Code.

Name of interface class when you generate C++ code with CppInterfaceStyle set to 'Methods'. In this case, the generated code for MATLAB entry-point functions consists of methods contained in a C++ class with name specified by CppInterfaceClassName. This property has no effect when you set CppInterfaceStyle to 'Functions'.

See Generate C++ Code with Class Interface.

Style of interface to the generated C++ code for the MATLAB entry-point functions that you generate code from. By default, entry-point functions become C++ functions. If you choose 'Methods', then entry-point functions become methods in a C++ class. Specify the name of the class by using the property CppInterfaceClassName.

See Generate C++ Code with Class Interface.

Namespace for the generated C++ code. The code generator does not produce code in a namespace unless you specify a nonempty character vector.

See C++ Code Generation.

Callback class for BLAS library calls in code generated for certain low-level vector and matrix operations in MATLAB code, specified as a character vector.

If you specify a BLAS callback class, for certain low-level vector and matrix functions, the code generator produces BLAS calls by using the CBLAS C interface to your BLAS library. The callback class provides the name of your CBLAS header file, the names of CBLAS data types, and the information required to link to your BLAS library. If this parameter is empty, the code generator produces code for matrix functions instead of a BLAS call.

See Speed Up Matrix Operations in Generated Standalone Code by Using BLAS Calls.

Callback class for FFTW library calls in code generated for FFT functions in MATLAB code, specified as a character vector.

To improve the execution speed of FFT functions, the code generator produces calls to the FFTW library that you specify in the callback class. If this parameter is empty, the code generator uses its own algorithms for FFT functions instead of calling the FFTW library.

See Speed Up Fast Fourier Transforms in Generated Standalone Code by Using FFTW Library Calls.

Custom code that appears near the top of each C/C++ header file generated from your MATLAB code, specified as a character vector.

Include folders to add to the include path when compiling the generated code. Specify the list of include folders as a character vector. In the character vector, separate include folders by a pathsep character. For example:

cfg = coder.config('lib','ecoder',false);
cfg.CustomInclude = ['C:\Project' pathsep 'C:\Custom Files'];

Custom code to include in the generated initialize function, specified as a character vector.

Callback class for LAPACK library calls in code generated for certain linear algebra functions in MATLAB code, specified as a character vector.

If you specify a LAPACK callback class, for certain linear algebra functions, the code generator produces LAPACK calls by using the LAPACKE C interface to your LAPACK library. The callback class provides the name of your LAPACKE header file and the information required to link to your LAPACK library. If this parameter is empty, the code generator produces code for linear algebra functions instead of a LAPACK call.

See Speed Up Linear Algebra in Generated Standalone Code by Using LAPACK Calls.

Static library files to link with the generated code, specified as a character vector. In the character vector, separate library file names by a pathsep character.

Source files to compile and link with the generated code, specified as a character vector. In the character vector, separate source file names by a pathsep character.

The build process searches for the source files first in the current folder, and then in the include folders that you specify in CustomInclude. If source files with the same name occur in multiple folders on the search path, the build process might use a different file than the file that you specified.

Suppose that you specify foo.cpp as a source file. If foo.c and foo.cpp are both on the search path, you cannot be sure whether the build process uses foo.c or foo.cpp.

Specify code to appear near the top of the generated .c or .cpp file, outside of any function. Specify code as a character vector.

Do not specify a C static function definition.

Code that appears in the generated terminate function, specified as a character vector.

Custom settings for tools in selected toolchain, specified as a cell array.

Dependencies:

  • The Toolchain property determines which tools and options appear in the cell array.

  • Setting the BuildConfiguration property to Specify enables CustomToolchainOptions.

First, get the current settings. For example:

cfg = coder.config('lib');
cfg.BuildConfiguration='Specify';
opt = cfg.CustomToolchainOptions

Then, edit the values in opt.

These values derive from the toolchain definition file and the third-party compiler options. See Custom Toolchain Registration.

Data type replacement in generated code, specified as one of the values in this table.

ValueDescription
'CBuiltIn'

This value is the default value.

The code generator uses built-in C data types.

'CoderTypeDefs'The code generator uses predefined data types from rtwtypes.h

Configuration object for code generation for deep learning networks, specified as a coder.MklDNNConfig object or a coder.ARMNEONConfig object.

A coder.MklDNNConfig object contains parameters specific to C++ code generation for deep learning using Intel® MKL-DNN. To create a coder.MklDNNConfig object, use coder.DeepLearningConfig. For example:

cfg = coder.config('mex');
cfg.TargetLang = 'C++';
cfg.DeepLearningConfig = coder.DeepLearningConfig('mkldnn');

A coder.ARMNEONConfig object contains parameters specific to C++ code generation for deep learning using the ARM® Compute Library. To create a coder.ARMNEONConfig object, use coder.DeepLearningConfig. For example:

cfg = coder.config('lib');
cfg.TargetLang = 'C++';
cfg.DeepLearningConfig = coder.DeepLearningConfig('arm-compute');

Code generation for deep learning networks requires Deep Learning Toolbox™ and the MATLAB Coder Interface for Deep Learning Libraries support package.

See Code Generation for Deep Learning Networks with MKL-DNN and Code Generation for Deep Learning Networks with ARM Compute Library.

Dependency: If DeepLearningConfig is set, codegen sets TargetLang to C++.

Object description, specified as a character vector.

Dynamic memory allocation mode, specified as one of the values in this table.

ValueDescription
'Threshold'

This value is the default value.

The code generator allocates memory dynamically on the heap for variable-size arrays whose size (in bytes) is greater than or equal to DynamicMemoryAllocationThreshold.

'AllVariableSizeArrays'The code generator dynamically allocates memory for all variable-size arrays on the heap.
'Off'

The code generator statically allocates memory for variable-size arrays on the stack.

Unbounded variable-size arrays require dynamic memory allocation.

Dependencies:

  • EnableVariableSizing enables this parameter.

  • Setting this DynamicMemoryAllocation to 'Threshold' enables the DynamicMemoryAllocationThreshold parameter.

See Generate Code for Variable-Size Data.

Size threshold for dynamic memory allocation of variable-size arrays, specified as a positive integer. The code generator uses dynamic memory allocation for variable-size arrays whose size (in bytes) is greater than or equal to the threshold.

Dependency:

  • Setting DynamicMemoryAllocation to 'Threshold' enables this parameter.

See Generate Code for Variable-Size Data.

Automatic extrinsic function calls, specified as one of the values in this table.

ValueDescription
true

This value is the default value.

The code generator treats some common visualization functions as extrinsic functions. You do not have to declare these functions as extrinsic by using coder.extrinsic. This capability reduces the amount of time that you spend making your code suitable for code generation.

falseThe code generator does not treat common visualization functions as extrinsic functions unless you declare them as extrinsic by using coder.extrinsic.

Some common visualization functions are plot, disp, and figure. See Extrinsic Functions.

memcpy optimization, specified as one of the values in this table.

ValueDescription
true

This value is the default value.

If possible, the code generator uses the memcpy optimization. To optimize code that copies consecutive array elements, the memcpy optimization replaces the code with a memcpy call. When the number of elements to copy is known at compile time, the code generator uses the MemcpyThreshold property to determine whether to use the optimization. See memcpy Optimization.

false

The code generator does not use the memcpy optimization.

Parallelization of parfor-loops, specified as one of the values in this table.

ValueDescription
true

This value is the default value.

If possible, the code generator uses the OpenMP library to produce loop iterations that run in parallel.

false

The code generator treats parfor-loops as for-loops.

See parfor.

Use of the OpenMP library is not compatible with just-in-time (JIT) compilation. If EnableJIT and EnableOpenMP are true, the code generator uses JIT compilation and treats parfor-loops as for-loops.

Run-time recursion support, specified as one of the values in this table.

ValueDescription
true

This value is the default value.

Recursive functions are allowed in the generated code.

false

Recursive functions are not allowed in the generated code.

Some coding standards, such as MISRA®, do not allow recursion. To increase the likelihood of generating code that is compliant with MISRA C®, set EnableRuntimeRecursion to false.

If your MATLAB code requires run-time recursion and EnableRuntimeRecursion is false, code generation fails.

See Code Generation for Recursive Functions.

Variable-size array support, specified as one of the values in this table.

ValueDescription
true

This value is the default value.

Variable-size arrays are allowed for code generation.

false

Variable-size arrays are not allowed for code generation.

Dependency:

  • Enables Dynamic memory allocation.

See Code Generation for Variable-Size Arrays.

File partitioning mode specified as one of the values in this table.

ValueDescription
'MapMFileToCFile'

This value is the default value.

The code generator produces separate C/C++ files for each MATLAB language file.

'SingleFile'The code generator produces a single file for C/C++ functions that map to your MATLAB entry-point functions. The code generator produces separate C/C++ files for utility functions.

See How MATLAB Coder Partitions Generated Code.

Generation of only source code, specified as one of the values in this table.

ValueDescription
false

This value is the default value.

The code generator produces C/C++ source code and builds object code.

true

The code generator produces C/C++ source code, but does not invoke the make command or build object code. When you iterate between modifying MATLAB code and generating C/C++ code, generating only code can save time.

Comments in generated code, specified as one of the values in this table.

ValueDescription
true

This value is the default value.

The code generator places comments in the generated code.

falseThe code generator does not place comments in the generated code.

Example C/C++ main file generation, specified as one of the values in this table.

ValueDescription
'GenerateCodeOnly'

This value is the default value.

The code generator generates an example C/C++ main function but does not compile it.

'DoNotGenerate'

The code generator does not generate an example C/C++ main function.

'GenerateCodeAndCompile'

The code generator generates an example C/C++ main function and compiles it to create a test executable. This executable does not return output.

If the GenCodeOnly parameter is true, the code generator does not compile the C/C++ main function.

An example main function is a template to help you to write a C/C++ main function that calls generated C/C++ code. See Incorporate Generated Code Using an Example Main Function.

Makefile generation during the build process, specified as one of the values in this table.

ValueDescription
true

This value is the default value.

The code generator generates a makefile during the build process.

falseThe code generator does not generate a makefile during the build process. Specify instructions for post-code-generation processing, including compilation and linking, in a post-code-generation command. See Build Process Customization.

Generation of support files for nonfinite data, specified as one of the values in this table.

ValueDescription
true

This value is the default value.

The code generator produces the support files for nonfinite data (Inf and NaN) only if the generated code uses nonfinite data.

false

The code generator always produces the support files for nonfinite data (Inf and NaN).

Dependency:

  • Setting SupportNonFinite to true enables this parameter.

Code generation report, specified as one of the values in this table.

ValueDescription
false

This value is the default value.

The code generator produces a report only if error or warning messages occur, or if you set LaunchReport to true.

trueThe code generator produces a code generation report.

Object that specifies a hardware board. To create the coder.Hardware object, use coder.hardware. For example:

cfg = coder.config('lib');
hw = coder.hardware('Raspberry Pi');
cfg.Hardware = hw;

Before you use coder.hardware, you must install the support package for the hardware.

Dependencies:

  • Setting Hardware customizes the hardware implementation object and other configuration parameters for a particular hardware board.

  • If DeepLearningConfig is set to a coder.ARMNEONConfig object and Hardware is empty, then codegen sets the GenCodeOnly property to true.

Note:

  • Suppose that you create a coder.CodeConfig object cfg in a MATLAB session and use it in another MATLAB session. If the MATLAB host computer for the second session does not have the hardware board specified in the cfg.Hardware property installed on it, this parameter reverts to its default value. The default value is [].

Hardware implementation object that specifies hardware-specific configuration parameters for C/C++ code generation. coder.config creates a coder.CodeConfig object with the HardwareImplementation property set to a coder.HardwareImplementation object with default parameter values for the MATLAB host computer.

To prevent compilation errors due to multiple inclusion of header files, the code generator produces either #ifndef or #pragma once constructs in generated header files. If your project uses distinct files that use the same preprocessor macros, then generate code with the #pragma once construct. The compilation behavior of #pragma once is not standardized.

Specify HeaderGuardStyle as one of the values in this table.

ValueDescription
UseIncludeGuard

The code generator produces #ifndef style #include guards.

UsePragmaOnceThe code generator produces #pragma once style #include guards.

Display of potential row-major layout efficiency issues, specified as one of the values in this table.

ValueDescription
true

The code generation report displays potential efficiency issues due to row-major layout. (This value is the default value.)

falseThe code generation report does not display issues related to array layout.

See Code Design for Row-Major Array Layout.

Assignment of float and double zero with memset, specified as one of the values in this table.

ValueDescription
true

This value is the default value.

If possible, the code generator uses the memset optimization for assignment of floating-point zero to consecutive array elements. To assign consecutive array elements, the memset optimization uses a memset call. When the number of elements to assign is known at compile time, the code generator uses the MemcpyThreshold property to determine whether to use the optimization. See memset Optimization.

false

The code generator does not use the memset optimization for assignment of float and double zero to consecutive array elements.

Stack size limit for inlined functions, specified as a positive integer. The stack size limit determines the amount of stack space allocated for local variables of the inlined function.

Specifying a limit for the stack space constrains the amount of inlining allowed. For out-of-line functions, stack space for variables local to the function is released when the function returns. However, for inlined functions, stack space remains occupied by the local variables even when the function returns.

This capability is especially important for embedded processors where stack size can be limited.

See Control Inlining.

Function size threshold for inlining, specified as a positive integer.

Unless other conditions prevent inlining, the code generator inlines functions that are smaller than the threshold.

The function size is measured as an abstract number of instructions, not actual MATLAB instructions or instructions in the target processor. To obtain the inlining behavior that you want, experiment with the threshold. For example, if the default threshold results in inlining of large functions and generation of large amounts of C code, tune the threshold until you are satisfied with the size of the generated code.

See Control Inlining.

Maximum size of functions after inlining, specified as a positive integer. If, after inlining, the size of the calling function exceeds InlineThresholdMax, then the code generator does not inline the called function.

The function size is measured as an abstract number of instructions, not actual MATLAB instructions or instructions in the target processor. To obtain the inlining behavior that you want, experiment with the threshold. For example, if the default threshold results in inlining of large functions and generation of large amounts of C code, tune the threshold until you are satisfied with the size of the generated code.

See Control Inlining.

Automatic open of code generation report, specified as one of the values in this table.

ValueDescription
false

This value is the default value.

If errors or warnings occur, or if GenerateReport is true, the code generator produces a report, but does not open the report.

trueThe code generator produces and opens a code generation report.

Loops with fewer iterations than this threshold are candidates for automatic unrolling by the code generator. This threshold applies to all for-loops in your MATLAB code. For an individual for-loop, a coder.unroll directive placed immediately before the loop takes precedence over the loop unrolling optimization. The threshold can also apply to some for-loops produced during code generation.

See Unroll for-Loops.

Inclusion of MATLAB source code as comments in generated code, specified as one of the values in this table.

ValueDescription
false

This value is the default value.

The code generator does not insert MATLAB source code as comments in the generated code. The code generator does not include the MATLAB function signature in the function banner.

true

The code generator inserts MATLAB source code as comments in the generated code. A traceability tag immediately precedes each line of source code. The traceability tag helps you to locate the corresponding MATLAB source code. See Tracing Generated C/C++ Code to MATLAB Source Code.

If you have Embedded Coder, in the code generation report, the traceability tag links to the source code.

The code generator also includes the MATLAB function signature in the function banner.

Dependency:

  • GenerateComments enables this parameter.

See Tracing Generated C/C++ Code to MATLAB Source Code.

Maximum number of characters in generated identifiers, specified as a positive integer in the range [31, 256]. This property applies to generated function, type definition, and variable names. To avoid truncation of identifiers by the target C compiler, specify a value that matches the maximum identifier length of the target C compiler.

This property does not apply to exported identifiers, such as the generated names for entry-point functions or emxArray API functions. If the length of an exported identifier exceeds the maximum identifier length of the target C compiler, the target C compiler truncates the exported identifier.

Minimum size, in bytes, for memcpy or memset optimization, specified as a positive integer.

To optimize generated code that copies consecutive array elements, the code generator tries to replace the code with a memcpy call. To optimize generated code that assigns a literal constant to consecutive array elements, the code generator tries to replace the code with a memset call.

The number of bytes is the number of array elements to copy or assign multiplied by the number of bytes required for the C/C++ data type.

If the number of elements to copy or assign is variable (not known at compile time), the code generator ignores the MemcpyThreshold property.

See memcpy Optimization and memset Optimization.

Multi-instance, reentrant code, specified as one of the values in this table.

ValueDescription
false

This value is the default value.

The code generator does not produce multi-instance, reentrant code.

true

The code generator produces reusable, multi-instance code that is reentrant.

See Reentrant Code. This option is not supported by the GPU Coder™ product.

Object name, specified as a character vector.

Output to build from generated C/C++ code, specified as one of the values in this table.

ValueDescription
'LIB'Static library
'DLL'Dynamically linked library
'EXE'Executable program

Pass structures by reference to entry-point functions, specified as one of the values in this table.

ValueDescription
true

This value is the default value.

The generated code passes structures by reference, which reduces memory usage and execution time by minimizing the number of copies of parameters at entry-point function boundaries.

Note

An entry-point function that writes to a field of a structure parameter overwrites the input value.

falseThe generated code passes structures by value.

This parameter applies only to entry-point functions.

See Pass Structure Arguments by Reference or by Value in Generated Code.

Command to customize build processing after MEX function generation with codegen, specified as a character vector.

See Build Process Customization.

Generation of code that uses N-dimensional indexing, specified as one of the values in this table.

ValueDescription
false

Generate code that uses one-dimensional indexing. (This value is the default value.)

trueGenerate code that uses N-dimensional indexing.

See Generate Code That Uses N-Dimensional Indexing.

Variable names to preserve in the generated code, specified as one of the values in this table.

ValueDescription
'None'

This value is the default value.

The code generator does not have to preserve any variable names. It can reuse any variables that meet the requirements for variable reuse.

If your code uses large structures or arrays, setting PreserveVariableNames to 'None' can reduce memory usage or improve execution speed.

'UserNames'

The code generator preserves names that correspond to variables that you define in the MATLAB code. It does not replace your variable name with another name and does not use your name for another variable. To improve readability, set PreserveVariableNames to 'UserNames'. Then, you can more easily trace the variables in the generated code back to the variables in your MATLAB code.

Setting PreserveVariableNames to 'UserNames' does not prevent an optimization from removing your variables from the generated code or prevent the C/C++ compiler from reusing the variables in the generated binary code.

'All'

Preserve all variable names. This parameter value disables variable reuse. Use it only for testing or debugging, not for production code.

See Preserve Variable Names in Generated Code.

Name of variable to which you export information about code generation, specified as a character vector. The code generator creates this variable in the base MATLAB workspace. This variable contains information about code generation settings, input files, generated files, and code generation messages.

See Access Code Generation Report Information Programmatically and coder.ReportInfo Properties.

Potential difference reporting, specified as one of the values in this table:

ValueDescription
trueThe code generator reports potential behavior differences between generated code and MATLAB code. The potential differences are listed on a tab of the code generation report. A potential difference is a difference that occurs at run time only under certain conditions.
falseThe code generator does not report potential differences.

See Potential Differences Reporting.

List of names that code generator must not use for functions or variables, specified as a character vector or string scalar. To specify multiple reserved names, use a semicolon-separated list of reserved names in ReservedNameArray. For example, cfg.ReservedNameArray = "reserve1;reserve2;reserve3".

Generation of code that uses row-major array layout, specified as one of the values in this table.

ValueDescription
false

Generate code that uses column-major array layout. (This value is the default value.)

trueGenerate code that uses row-major array layout.

See Generate Code That Uses Row-Major Array Layout.

Generation of a call to the initialize function at the beginning of the generated entry-point functions, specified as one of the values in this table.

ValueDescription
true

This value is the default value.

A call to the initialize function is included at the beginning of the generated entry-point functions. The generated code includes checks to make sure that the initialize function is called only once, even if there are multiple entry-point functions.

false

The generated entry-point functions do not include calls to the initialize function.

See Use Generated Initialize and Terminate Functions.

Run-time error detection and reporting in generated code, specified as one of the values in this table.

ValueDescription
false

This value is the default value.

The generated code does not check for errors such as out-of-bounds array indexing.

true

The generated code checks for errors such as out-of-bounds array indexing.

The error-reporting software uses fprintf to write error messages to stderr. It uses abort to terminate the application. If fprintf and abort are not available, you must provide them. The abort function abruptly terminates the program. If your system supports signals, you can catch the abort signal (SIGABRT) so that you can control the program termination.

Error messages are in English.

See Run-Time Error Detection and Reporting in Standalone C/C++ Code.

Integer overflow support, specified as one of the values in this table.

ValueDescription
true

This value is the default value.

The code generator produces code to handle integer overflow. Overflows saturate to either the minimum or maximum value that the data type can represent.

false

The code generator does not produce code to handle integer overflow. Do not set SaturateOnIntegerOverflow to false unless you are sure that your code does not depend on integer overflow support. If you disable integer overflow support and run-time error checking is enabled, the generated code produces an error for overflows. If you disable integer overflow support and you disable run-time error checking, the overflow behavior depends on your target C compiler. In the C standard, the behavior for integer overflow is undefined. However, most C compilers wrap on overflow.

This parameter applies only to MATLAB built-in integer types. It does not apply to doubles, singles, or fixed-point data types.

See Disable Support for Integer Overflow or Nonfinites.

Maximum stack usage per application, in bytes, specified as a positive integer. Set a limit that is lower than the available stack size. Otherwise, a run-time stack overflow might occur. The C compiler detects and reports stack overflows.

See Disable Support for Integer Overflow or Nonfinites.

Support for nonfinite values, specified as one of the values in this table.

ValueDescription
true

This value is the default value.

If GenerateNonFiniteFilesIfUsed is set to true, the code generator produces code to support nonfinite values (Inf and NaN) only if they are used.

If GenerateNonFiniteFilesIfUsed is set to false, the code generator always produces code to support nonfinite values (Inf and NaN).

false

The code generator does not produce code to support nonfinite values.

See Disable Support for Integer Overflow or Nonfinites.

Language to use in generated code, specified as 'C' or 'C++'. If you specify C++, the code generator wraps the C code into .cpp files so that you can use a C++ compiler and interface with external C++ applications. It does not generate C++ classes.

Dependency: If DeepLearningConfig is set, codegen sets TargetLang to C++.

Standard math library to use for the generated code, specified as one of these character vectors:

  • 'C89/C90 (ANSI)'

  • 'C99 (ISO)'

  • 'C++03 (ISO)'

The code generator uses the standard math library for calls to math operations. The default standard math library depends on the language that you select. For C, the default library is 'C99 (ISO)'. For C++, the default library is 'C++03 (ISO)'.

See Change the Standard Math Library.

Toolchain to use for building a C/C++ library or executable program, specified as a character vector. The list of available toolchains depends on the host computer platform, and can include custom toolchains that you added. If you do not specify a toolchain, the code generator locates an installed toolchain.

Note:

  • Suppose that you create a coder.CodeConfig object cfg in a MATLAB session and use it in another MATLAB session. If the MATLAB host computer for the second session does not have the toolchain specified in the cfg.Toolchain property installed on it, this parameter reverts to its default value. The default value is 'Automatically locate an installed toolchain'.

Code generation progress display, specified as one of the values in this table.

ValueDescription
false

This value is the default value.

The code generator does not display code generation progress.

true

The code generator displays code generation progress, including code generation stages and compiler output.

Examples

collapse all

Write a MATLAB function from which you can generate code. This example uses the function myadd that returns the sum of its inputs.

function c = myadd(a,b)
c = a + b;
end

Create a configuration object for generation of standalone C/C++ code (a static library, a dynamically linked library, or an executable program). For example, create a configuration object for generation of a static library.

cfg = coder.config('lib');

Change the values of the properties for which you do not want to use the default values. For example, enable run-time error detection and reporting in the generated C/C++ code.

cfg.RuntimeChecks = true;

Generate code by using codegen. Pass the configuration object to codegen by using the -config option. Specify that the input arguments are scalar double.

codegen myadd -config cfg -args {1 1} -report

Alternative Functionality

To use default configuration parameters for build types 'LIB', 'DLL', or 'EXE', use the codegen option -config:lib, -config:dll, or -config:exe, respectively. Then, you do not have to create and pass a configuration object to codegen.

Introduced in R2011a