Main Content

Create Block Library from C/C++ Code

Create Simulink® libraries from C/C++ code with the Simulink Code Importer

Use the Simulink Code Importer tool to build a Simulink library from your custom C/C++ code library. The Simulink Code Importer brings custom code into a Simulink library of C Caller blocks as callable functions, after analyzing the custom code for functions and their dependencies, including global variables and types used by the functions.

The Simulink Code Importer imports custom C++ class into a library of C Function blocks after analyzing the custom code for classes and their dependencies. (since R2024a)

To use the Simulink Code Importer, go to the Modeling tab on the Simulink toolstrip. From Design, choose Code Importer. A series of screens then leads you through the process of creating a Simulink library from your custom code.

Alternatively, you can create an object of the Simulink.CodeImporter class and run the Simulink Code Importer tool using a command-line interface.

If you have a Simulink Test™ license, you can use the Simulink Code Importer to perform unit testing or integration testing on your custom C/C++ code. See Importing and Testing Custom C/C++ Code (Simulink Test).

Classes

Simulink.CodeImporterImport custom C/C++ code into Simulink (Since R2021a)
Simulink.CodeImporter.CustomCodeSpecify custom code settings for Simulink.CodeImporter and sltest.CodeImporter classes (Since R2021a)
Simulink.CodeImporter.OptionsSpecify additional import options for Simulink.CodeImporter and sltest.CodeImporter classes (Since R2021a)
Simulink.CodeImporter.ParseInfoInformation about parsed custom code (Since R2021a)
Simulink.CodeImporter.FunctionAccess and configure detailed information about parsed custom code functions (Since R2021a)
Simulink.CodeImporter.SimulinkPortSpecificationConfigure port specification for imported custom code (Since R2021a)

Blocks

C CallerIntegrate C code in Simulink
C FunctionIntegrate and call external C/C++ code from a Simulink model (Since R2020a)

Topics