Main Content

Generate C/C++ Code

After you prepare your MATLAB® code for code generation, specify input types, and check your code for issues, you can generate standalone C/C++ code or an accelerated MEX function. See the Code Generation Workflow.

Generate Standalone C/C++ Code

To generate standalone C/C++ code:

  • In the MATLAB Coder™ app, on the Generate Code page, click Generate.

  • At the command line, pass your entry-point functions to the codegen function and use the -config option to specify a standalone C/C++ output type. See Configure Code Generation and Build Settings.

After you generate standalone C/C++ code, you can:

  • Create a standalone C/C++ executable and deploy this application on a target platform.

  • Integrate the generated source code or library into an existing C/C++ project.

  • Run the generated code on embedded microprocessors by using a toolchain.

  • Package the generated code for transfer to another development environment.

For details, see Deploy Generated Code and Package Code for Other Development Environments.

Generate an Accelerated MEX Function

To generate an accelerated MEX function:

  • Review the available optimization strategies. In particular, consider unrolling for-loops and parfor-loops, inlining small functions, and passing variables by reference. See Optimize Generated C/C++ and MEX Code.

  • Disable run-time checks. You should only disable run-time checks if you have checked your MATLAB code for issues by following the Code Generation Workflow. To disable run-time checks, see Control Run-Time Checks.

After you generate an accelerated MEX, you can explore further opportunities for acceleration by using the MATLAB Profiler to identify portions of the generated MEX function that are highly time-intensive. See Profile MEX Functions by Using MATLAB Profiler.

Accelerated MEX functions can be used to speed applications and simulations in a number of different toolboxes. For example:

See Also

Related Examples

More About

External Websites