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
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.
SourceFiles
— Source files to be imported
cell array of character vectors | string array
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
InterfaceHeaders
— Interface headers to be imported
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
IncludePaths
— Folders containing included header files
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
— Libraries that contain custom object code to link
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
Defines
— Preprocessor macro definitions to be added to the compiler command line
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
Language
— Custom code language
'C'
(default) | 'C++'
Custom code language, specified as 'C'
or
'C++'
. C and C++ are the only supported languages.
Data Types: character vector
| string scalar
CompilerFlags
— Additional compiler flags
cell array of character vectors | string array
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
LinkerFlags
— Additional linker flags
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
GlobalVariableInterface
— Option to enable or disable automatic addition or deletion of global variables as function interfaces
false
(default) | true
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
FunctionArrayLayout
— Default array layout for custom code functions
NotSpecified
(default) | RowMajor
| ColumnMajor
| Any
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
Specify Custom Code for Import
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
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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)