Main Content

Generating Code

Generate code and build standalone libraries and executables

C/C++ code generation is the core functionality of MATLAB® Coder™. Generate code from the app, which you can open with coder, or from the command line, by using the codegen function. The app provides step-by-step guidance through the code generation process, including guidance for best practices, and clear visual aids for the code generation settings and options. The command line workflow enables simple, repeatable, and efficient initiation of code generation. The code generation workflow supports many different data types, including variable-size data and global data. The workflow also supports multiple entry-point (top-level) functions, multisignature MEX (polymorphic MEX) function generation, and customization of fundamental properties such as the array layout and array indexing of the generated code. In addition, you can generate code that uses key C++ language features such as classes, namespaces, and function overloading.

Apps

expand all

MATLAB CoderGenerate C code or MEX function from MATLAB code

Functions

expand all

coderOpen MATLAB Coder app
codegenGenerate C or C++ code from MATLAB code
coder.targetDetermine if code generation target is specified target
coder.allowpcodeControl code generation from P-code files
coder.configCreate code generation configuration objects
coder.extrinsicDeclare function as extrinsic and execute it in MATLAB
coder.loadLoad constants from MAT file or ASCII file at code generation time
coder.nullcopyDeclare uninitialized variables in generated code
coder.readRead data files at run time in generated code (Since R2023a)
coder.writeCreate data files that the generated code reads at run time (Since R2023a)
RTW.reservedIdentifiersGet reserved identifiers for code generation (Since R2023b)
coder.newtypeCreate coder.Type object to represent type of an entry-point function input
coder.varsizeResolve size incompatibility errors and declare upper bounds
coder.typeofCreate coder.Type object to represent the type of an entry-point function input
coder.resizeResize coder.Type object

Topics

Generating Code Basics

Switch Between Command Line and Project Workflows

Data-specific Workflows

Extended Functionality

Extended C++ Functionality

Code Appearance

  • Reserved Keywords
    Certain words in your code, that are C/C++ keywords, might be renamed in the generated code.

Featured Examples