Main Content

External Code Integration

Call external code from MATLAB® code

When you have external code, custom code, or legacy code developed in C/C++, you can integrate it directly into your MATLAB code. For example:

  • To call C/C++ functions, use the coder.ceval function. The code generator integrates your C/C++ code into the C/C++ code generated from MATLAB. Integrate code when there are external libraries, optimized code, or object files developed in C/C++ that you want to use with your generated code.

  • To pass data types to or from the external code that are not definable in MATLAB code, such as pointer types or FILE types for external file I/O, use the coder.opaque function.

  • To configure your build to include and link to external source files, header files, object files, and libraries, use the coder.updateBuildInfo function.

  • To provide an object-oriented interface to an external C library, package your function calls into a class derived from the coder.ExternalDependency superclass.

  • To reserve certain identifier names for use in the custom C/C++ code that you want to integrate with the generated code, use the coder.reservedName function.

  • To interface with an external structure type, use the coder.cstructname function.

Classes

coder.ExternalDependencyInterface to external code
coder.BuildConfigBuild context during code generation

Functions

coder.cevalCall C/C++ function from generated code
coder.refIndicate data to pass by reference
coder.rrefIndicate read-only data to pass by reference
coder.wrefIndicate write-only data to pass by reference
coder.cincludeInclude header file in generated code
coder.opaqueDeclare variable in generated code
coder.reservedNameGenerate code that does not use specified identifier names
coder.updateBuildInfoUpdate RTW.BuildInfo build information object

Topics

Troubleshooting

Resolve Error: Unknown Output Type for coder.ceval

Troubleshoot error when the code generator is unable to determine the output type of an external C/C++ function call.

Featured Examples