Main Content

Simulink.CodeImporter.CustomCode Class

Namespace: Simulink.CodeImporter

Specify custom code settings for Simulink.CodeImporter and sltest.CodeImporter classes

Since R2021a

Description

The Simulink.CodeImporter.CustomCode class is a handle class.

Creation

When you create an object of class Simulink.CodeImporter, an object of class Simulink.CodeImporter.CustomCode is automatically created as the CustomCode property of that object. Do not create an object of class Simulink.CodeImporter.CustomCode directly.

Properties

expand all

Note

The first four properties listed below (SourceFiles, InterfaceHeaders, IncludePaths, and Libraries) let you specify file path information about the location of your custom code. To enable portability, specify this information as a file path relative to the folder specified in the OutputFolder property of the relevant Simulink.CodeImporter object rather than as an absolute path.

Source files to be imported, specified as a cell array of character vector or a string array. Supported files include .c and .cpp files. Each file name can be specified as a path relative to the folder specified in the OutputFolder property of the relevant Simulink.CodeImporter object or as an absolute path.

Providing a value for SourceFiles is optional for Simulink.CodeImporter and optional for sltest.CodeImporter when the TestType is IntegrationTest.

Example: {'foo.c', 'bar.c'}

Example: [".\foo.c", "..\bar.c"]

Example: fullfile(pwd, 'Src', 'foo.c')

Data Types: cell array of character vectors | string array

Interface headers to be imported, specified as a cell array of character vectors or a string array. Supported files include .h and .hpp files. Each file name can be specified as a path relative to the folder specified in the OutputFolder property of the relevant Simulink.CodeImporter object or as an absolute path. Interface headers should contain the function declarations and type definitions that you want to bring into Simulink®. These declarations and definitions are usually contained in the export header of your C code library.

Example: {'foo.h', 'bar.h'}

Example: [".\foo.h", "..\bar.h"]

Example: fullfile(pwd, 'Hdr', 'foo.h')

Data Types: cell array of character vectors | string array

Folders containing included header files for the parser to find, specified as a cell array of character vectors or a string array. Each folder path can be specified as a path relative to the folder specified in the OutputFolder property of the relevant Simulink.CodeImporter object or as an absolute path.

Example: {'.', '..\..'}

Example: [".\Include1", "..\Include2"]

Example: fullfile(pwd, 'Include1')

Data Types: cell array of character vectors | string array

Libraries that contain custom object code to link, specified as a cell array of character vectors or a string array. Supported files include .obj, .dll, .lib, .so, .o, .a, and .dylib files. Each file name can be specified as a path relative to the folder specified in the OutputFolder property of the relevant Simulink.CodeImporter object or as an absolute path.

Providing libraries is optional.

Example: {'foo.lib', 'foo.dll'}

Example: [".\foo.so", "..\bar.so"]

Data Types: cell array of character vectors | string array

Preprocessor macro definitions to be added to the compiler command line, specified as a cell array of character vectors or a string array. '-D' is optional in defines.

Example: {'-D DEF1', '-D DEF2'}

Example: ["DEF1", "DEF2"]

Data Types: cell array of character vectors | string array

Custom code language, specified as 'C' or 'C++'. C and C++ are the only supported languages.

Data Types: character vector | string scalar

Additional compiler flags to be added to the compiler command line, specified as a cell array of character vectors or a string array.

Example: {'/O2' , '/Og'}

Example: "-g"

Data Types: cell array of character vectors | string array

Additional linker flags to be added to the linker command line, specified as a cell array of character vectors or a string array.

Example: {'/WX'}

Data Types: cell array of character vectors | string array

Option to enable or disable automatic addition or deletion of global variables from custom code called by C Caller block. If set to true, global variables accessed by the custom code functions will be automatically treated as function interfaces in the generated Simulink library. See Call C Caller Block and Specify Ports and Automatically infer global variables as function interfaces.

Data Types: logical scalar

Default array layout for custom code functions to use to access input argument arrays, specified as NotSpecified, RowMajor, ColumnMajor, or Any. You can override the default for an individual function by using the ArrayLayout property of the Simulink.CodeImporter.Function object corresponding to that function. Matrix data passed to and from your C functions is converted to the function array layout you specify. See Integrate C Code Using C Caller Blocks and Default function array layout.

Data Types: enum

Examples

collapse all

Create an object of class Simulink.CodeImporter. Set the properties of its CustomCode property to specify custom code to import into Simulink.

obj = Simulink.CodeImporter("pumpController");

obj.OutputFolder = ".";

obj.CustomCode.InterfaceHeaders = ["pumpController.h"];
obj.CustomCode.IncludePaths = ["./include"];
obj.CustomCode.SourceFiles = ["src/pumpController.c" "src/utils.c"];

Version History

Introduced in R2021a