External Code Integration
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.cevalfunction. 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
FILEtypes for external file I/O, use thecoder.opaquefunction.To configure your build to include and link to external source files, header files, object files, and libraries, use the
coder.updateBuildInfofunction.To provide an object-oriented interface to an external C library, package your function calls into a class derived from the
coder.ExternalDependencysuperclass.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.reservedNamefunction.To interface with an external structure type, use the
coder.cstructnamefunction.
Classes
coder.ExternalDependency | Interface to external code |
coder.BuildConfig | Build context during code generation |
Functions
coder.ceval | Call C/C++ function from generated code |
coder.ref | Indicate data to pass by reference |
coder.rref | Indicate read-only data to pass by reference |
coder.wref | Indicate write-only data to pass by reference |
coder.cinclude | Include header file in generated code |
coder.opaque | Declare variable in generated code |
coder.reservedName | Generate code that does not use specified identifier names |
coder.updateBuildInfo | Update RTW.BuildInfo build information object |
Topics
- Configure Build for External C/C++ Code
Specify source files and build parameters for external C/C++ code.
- Integrate External Code That Uses Pointers, Structures, and Arrays
Integrate external C code that uses pointers, structures, and arrays into MATLAB code.
- Pass by Reference to and from External C Functions
Pass data by reference to and from an external C function.
- Integrate External Code That Uses Custom Data Types
Use C types that are not native to MATLAB in an external function.
- Develop Interface for External C/C++ Code
Access your external code using a class interface.
- Mapping MATLAB Types to Types in Generated Code
Understand how the code generator maps MATLAB data types to data types in the generated C/C++ code.
- Integrate Multiple Generated C++ Code Projects
Integrate the generated C++ code from two projects into a single larger project.
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.
