Package: coder
codegen
configuration object
A coder.CodeConfig
object contains the configuration
parameters that the codegen
function requires
to generate standalone C/C++ libraries and executables. Use the -config
option
to pass this object to the codegen
function.
creates a code generation configuration
object for C/C++ static library generation. If the Embedded Coder® product
is not installed, it creates a cfg
=
coder.config('lib')coder.CodeConfig
object.
Otherwise, it creates a coder.EmbeddedCodeConfig
object.
creates a code generation configuration
object for C/C++ dynamic library generation. If the Embedded Coder product
is not installed, it creates a cfg
=
coder.config('dll')coder.CodeConfig
object.
Otherwise, it creates a coder.EmbeddedCodeConfig
object.
creates
a code generation configuration object for C/C++ executable generation.
If the Embedded Coder product is not installed, it creates a cfg
= coder.config('exe')coder.CodeConfig
object.
Otherwise, it creates a coder.EmbeddedCodeConfig
object.
creates a cfg
= coder.config(output_type
,
'ecoder', false)coder.CodeConfig
object
for the specified output type even if the Embedded Coder product
is installed.
creates a cfg
= coder.config(output_type
,
'ecoder', true)coder.EmbeddedCodeConfig
object
for the specified output type even if the Embedded Coder product
is not installed. However, you cannot generate code using a coder.EmbeddedCodeConfig
object
unless an Embedded Coder license is available.
|
Specify build configuration. Default: | |||||||||||||||||||||||
|
Specify a code replacement library for the generated code.
Compatible libraries depend on these parameters:
Embedded Coder offers more libraries and the ability to create and use custom code replacement libraries. MATLAB® Coder™ generates the minimal set of 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.
Default: | |||||||||||||||||||||||
|
For compile-time recursion, control the number of copies of
a function that are allowed in the generated code. To disallow recursion
in the MATLAB code, set Default: | |||||||||||||||||||||||
|
Specify the maximum number of instructions that the constant folder will execute before stopping. In some situations, code generation might require specific instructions to be constant. Increase this value if code generation is failing. Default: | |||||||||||||||||||||||
|
Specify code to appear near the top of each C/C++ header file generated from your MATLAB algorithm code. Specify code as a character vector. Default: | |||||||||||||||||||||||
|
Specify a space-separated list of include folders to add to the include path when compiling the generated code. Specify list of include folders as a character vector. If your list includes Windows paths that contain spaces, enclose each instance in double quotes, for example: 'C:\Project "C:\Custom Files"' Default: | |||||||||||||||||||||||
|
Specify code to appear in the initialize function of the generated Default: | |||||||||||||||||||||||
|
Specify the name of a LAPACK callback class that derives from Default: | |||||||||||||||||||||||
|
Specify a space-separated list of static library or object files to link with the generated code. Specify list as a character vector. Default: | |||||||||||||||||||||||
|
Specify a space-separated list of source files to compile and link with the generated code. Specify list of source files as a character vector. Default: | |||||||||||||||||||||||
|
Specify code to appear near the top of the generated Default: | |||||||||||||||||||||||
|
Specify code to appear in the terminate function of the generated Default: | |||||||||||||||||||||||
|
Specify custom settings for each tool in the selected toolchain, as a cell array. Dependencies:
Start by getting the current options and values. For example: rtwdemo_sil_topmodel; set_param(gcs, 'BuildConfiguration', 'Specify') opt = get_param(gcs, 'CustomToolchainOptions') Then edit the values in These values derive from the toolchain definition file and the third-party compiler options. See Custom Toolchain Registration. Default: | |||||||||||||||||||||||
|
Specify whether to use built-in C data types or pre-defined
types from Set to Default: | |||||||||||||||||||||||
|
Description of the Default: | |||||||||||||||||||||||
|
Control use of dynamic memory allocation for variable-size data. By default, dynamic memory allocation is enabled for variable-size
arrays whose size (in bytes) is greater than or equal to Set this property to Dependencies:
Default: | |||||||||||||||||||||||
|
Specify the size threshold in bytes. Dependency:
Default: | |||||||||||||||||||||||
|
Specify whether MATLAB Coder must treat common visualization
functions as extrinsic functions. When this option is enabled, MATLAB Coder detects
calls to many common visualization functions, such as Default: | |||||||||||||||||||||||
|
Enable the
See memcpy Optimization. Default: | |||||||||||||||||||||||
|
If possible, enable OpenMP. Using the OpenMP library, the C/C++
code that MATLAB Coder generates for Default: | |||||||||||||||||||||||
|
Allow recursive functions in generated code. If your MATLAB code
requires run-time recursion and this parameter is Some coding standards, such as MISRA®, do not allow recursion.
To increase the likelihood of generating code that is compliant with MISRA C®,
set Default: | |||||||||||||||||||||||
|
Enable support for variable-size arrays. Dependency:
Default: | |||||||||||||||||||||||
|
Specify whether to generate one C/C++ file for each MATLAB language
file ( Default: | |||||||||||||||||||||||
|
Specify code generation versus an executable or static library build. Default: | |||||||||||||||||||||||
|
Place comments in the generated files. Dependency:
Default: | |||||||||||||||||||||||
|
Specify whether to generate an example C/C++ main function.
If example main generation is enabled, MATLAB Coder generates
source and header files for the main function in the The example main function declares and initializes data. It calls entry-point functions but does not use values returned from the entry-point functions. Before you use the example main files, copy them to another location and modify them to meet the requirements of your application.
Default: | |||||||||||||||||||||||
|
Specify whether to generate a makefile during the build process. Default: | |||||||||||||||||||||||
|
Document generated code in an HTML report. Default: | |||||||||||||||||||||||
|
Handle to | |||||||||||||||||||||||
|
Enable the
See memset Optimization. Default: | |||||||||||||||||||||||
|
Specify the stack size limit on inlined functions. This specification determines the amount of stack space allocated for local variables of the inlined function. Specifying a limit on 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 feature is especially important for embedded processors, where stack size can be limited. Default: | |||||||||||||||||||||||
|
Specify function size for inline threshold. Unless there are conflicts with other inlining conditions, MATLAB Coder inlines functions that are smaller than this size. The function size is measured in terms of an abstract number of instructions, not actual MATLAB instructions or instructions in the target processor. You must experiment with this parameter to obtain the inlining behavior that you want. For instance, if the default setting for this parameter is leading to large functions being inlined and in turn generating large C code, you can tune the parameter in steps until you are satisfied with the size of generated code. Default: | |||||||||||||||||||||||
|
Specify the maximum size of functions after inlining. If the
size of the calling function after inlining exceeds The function size is measured in terms of an abstract number of instructions, not actual MATLAB instructions or instructions in the target processor. You must experiment with this parameter to obtain the inlining behavior that you want. For instance, if the default setting for this parameter is leading to large functions being inlined and in turn generating large C code, you can tune the parameter in steps until you are satisfied with the size of generated code. Default: | |||||||||||||||||||||||
|
Specify whether to display a report after code generation is complete or an error occurs. Default: | |||||||||||||||||||||||
|
Include MATLAB source code as comments in the generated code. Dependency:
Default: | |||||||||||||||||||||||
|
Specify maximum number of characters in 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 parameter 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 is 31. Maximum is 256. Default: | |||||||||||||||||||||||
|
Specify the minimum number of bytes for the code generatorto
invoke the 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. See memcpy Optimization and memset Optimization. Default: | |||||||||||||||||||||||
|
Generate reusable, multi-instance code that is reentrant. Default: | |||||||||||||||||||||||
|
Name of the configuration object. Default: | |||||||||||||||||||||||
|
Specify whether to generate a standalone C/C++ static library,
dynamic library, or executable. Set to Default: | |||||||||||||||||||||||
|
Specify whether to pass structures by reference to entry-point
functions. Set to This parameter applies only to entry-point functions. If you set this parameter to Default: | |||||||||||||||||||||||
|
Specify command to customize build processing after code generation
using Default: | |||||||||||||||||||||||
|
Specify which variable names the code generator must preserve in the generated code.
Default: | |||||||||||||||||||||||
|
Enter a space-separated list of names that MATLAB Coder is not to use for naming functions or variables. Specify list as a character vector. Default: | |||||||||||||||||||||||
|
Enable run-time error detection and reporting in the generated C/C++ code. If you select this option, the generated code checks for errors such as out-of-bounds array indexing. The error reporting software uses Error messages are in English. Default: | |||||||||||||||||||||||
|
Overflows saturate to either the minimum or maximum value that the data type can represent. Otherwise, the overflow behavior depends on your target C compiler. 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. Default: | |||||||||||||||||||||||
|
Specify the maximum stack usage per application in bytes. Set a limit that is lower than the available stack size. Otherwise, a run-time stack overflow can occur. The C compiler detects and reports overflows. Default: | |||||||||||||||||||||||
|
Specify whether to generate nonfinite data and operations. Default: | |||||||||||||||||||||||
|
Specify the target language. Set to Default: | |||||||||||||||||||||||
|
Specify a standard math library for the generated code. Options
include 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. Default: | |||||||||||||||||||||||
|
Specify the toolchain to use. If you do not specify a toolchain, MATLAB Coder automatically locates an installed toolchain. Default: | |||||||||||||||||||||||
|
Display code generation progress. Default: |
Handle. To learn how handle classes affect copy operations, see Copying Objects in the MATLAB documentation.
Generate a standalone C/C++ static library from a MATLAB function that is suitable for code generation:
Write a MATLAB function, coderand
,
that generates a random scalar value from the standard uniform distribution
on the open interval (0,1).
function r = coderand() %#codegen % The directive %#codegen declares that the function % is intended for code generation r = rand();
Create a code generation configuration object to generate a static library.
cfg = coder.config('lib')
Generate the C library files in the default folder
(codegen/lib/coderand). Use the -config
option
to specify the configuration object.
codegen -config cfg coderand
Generate a C executable file from a MATLAB function that is suitable for code generation. Specify the main C function as a configuration parameter.
Write a MATLAB function, coderand
,
that generates a random scalar value from the standard uniform distribution
on the open interval (0,1).
function r = coderand() %#codegen r = rand();
Write a main C function, c:\myfiles\main.c, that calls coderand
.
/* ** main.c */ #include <stdio.h> #include <stdlib.h> #include "coderand.h" int main() { coderand_initialize(); printf("coderand=%g\n", coderand()); coderand_terminate(); return 0; }
Configure your code generation parameters to include the main C function, then generate the C executable.
cfg = coder.config('exe'); cfg.CustomSource = 'main.c'; cfg.CustomInclude = 'c:\myfiles'; codegen -config cfg coderand
codegen
generates C executables and supporting
files in the default folder codegen/exe/coderand
.
This example shows how to specify a main function as a parameter
in the configuration object coder.CodeConfig
. Alternatively,
you can specify the file containing main() separately on the command
line. You can use a source, object, or library file.
Use the coder
function to create a MATLAB Coder project.
The project provides a user interface that facilitates adding MATLAB files,
defining input parameters, and specifying build parameters.